you might need to implement your own @compile for BindParam which does extra 
work based on some new **kw that you can send through to process(), or if your 
special **kw isn't present, calls compiler.visit_bindparam(param).




On Jul 23, 2013, at 12:29 PM, matt g <[email protected]> wrote:

> The literal_binds looks great. Do you know of a function that I can use that 
> will take the string from compiler.process(select_statement, 
> literal_binds=True) and escapes the single quotes in that string? 
> 
> For instance, if I have the following (assuming that the table object has 
> already been defined):
> select_statment = select([func.count(), table.c.year], 
> from_obj=table).where(table.c.year.in_([2011,2012])).group_by(table.c.year)
> sql_string = compiler.process(select_statement, literal_binds=True)
> 
> sql_string looks like this:
> u"SELECT count(*) AS count_2, inpatient.year \nFROM inpatient \nWHERE 
> inpatient.year IN ('2011', '2012') GROUP BY inpatient.year"
> 
> according to the redshift docs, i need to take that string and now escape 
> single quotes it before adding it into the unload statement my 
> UnloadFromSelect clause is creating: 
> If your query contains quotes (enclosing literal values, for example), you 
> need to escape them in the query text. For example:
> ('select * from venue where venuestate=\'NV\'')
> 
> 
> 
> 
> On Tuesday, July 23, 2013 10:22:09 AM UTC-5, Michael Bayer wrote:
> 
> On Jul 23, 2013, at 11:09 AM, matt g <[email protected]> wrote: 
> 
> > Hi, 
> > We are using sqlalchemy with Amazon Redshift. One of the things that I 
> > wanted to do was to create a custom construct for Redshift's unload 
> > statement. I modified the sample InsertFromSelect 
> > (http://docs.sqlalchemy.org/en/rel_0_8/core/compiler.html?highlight=insertfromselect).
> >  However, we are having problems because the 
> > UNLOAD(http://docs.aws.amazon.com/redshift/latest/dg/r_UNLOAD.html) 
> > statement requires that the internal select be wrapped in single quotes. 
> > What would be the best way to ensure that the bind params for the enclosing 
> > select clause be escaped properly? 
> 
> why do bound parameters need to be escaped?  you mean they have to be 
> rendered out inline ?    If that's the case, set the literal_binds keyword 
> arg to True when you pass along to compiler.process().
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to