On Aug 18, 2011, at 2:01 PM, Marc DellaVolpe wrote:

> I understand what you are saying about this being an uphill battle on mssql.
> 
> If we ignore the CTE for the moment and pretend that all_dates is a regular 
> table, shouldn't there be no difference for generation.   You can subquery as 
> needed and all that really needs to happen is to prepend the CTE to the rest 
> of the SQL before execution.  Maybe this approach isn't generally applicable, 
> CTE's already make my head hurt :)

yeah that could work as well but its not clear to me if the CTE can be up above 
everything, then referenced within a nested structure like that.    I haven't 
really worked with CTEs to have that level of experience.

> 
> Searching the mailing list found a thread 
> (http://groups.google.com/group/sqlalchemy/browse_thread/thread/c20a4f380e277af/fb179a515bf48868)
>  where you used a regular expression to shim in a special comment.  This 
> seems hackish but could a similar approach work on mssql? Is it possible to 
> hook into only the top-level/last Select's compile()?

if it works, then yes you'd get your Select compiler to dig in, look for CTEs, 
put the WITH all the way on top, assuming the Select is the "outermost".  You 
can tell if you're the "outermost" select by checking "bool(compiler.stack)", 
which is a stack of SELECT constructs.


-- 
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.

Reply via email to