On Jul 17, 2012, at 2:25 PM, Russ wrote: > For future reference, it is not actually a great idea to use @compiles to > render with "AT TIME ZONE" as I did above. When done this way, SQLAlchemy > renders all references to that column using this, including any references in > a WHERE clause. eg: when looking for log events later than some date you > would get: > > SELECT > log.blah > ,log.time AT TIME ZONE 'EST' -- intended use > FROM > log > WHERE > log.time AT TIME ZONE 'EST' > foo -- not intended > > As said above, the problem here is that the custom compilation happened in > both the column specification and the WHERE clause. This is not surprising > (with hindsight), but it prevents any index on log.time from being used > (unless there is an appropriate functional index). > > For this case, I only wanted it applied to the column spec, not the WHERE, > but I don't think this is currently possible to differentiate this and > compile differently in each location... or is it? I looked into > compiler.statement et al to figure out the compilation context, but could not.
it is, you need to look in the **kw passed to your custom compile function for the flag "within_columns_clause=True", which indicates it's rendering the columns clause. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.