On Aug 18, 2011, at 1:28 PM, Marc DellaVolpe wrote:

> There seems to be a problem with the custom compilation.
> 
> >>> print Session.query(Date).order_by(Date.date.desc())
> 
> WITH all_dates(date) AS (
> SELECT CAST(:start AS DATETIME) AS anon_1 UNION ALL SELECT DATEADD(dd, :step, 
> date) AS "DATEADD_1" 
> FROM all_dates 
> WHERE DATEADD(dd, :step, date) <= CAST(:stop AS DATETIME)
> )
> SELECT * FROM all_dates
> OPTION (MAXRECURSION 0)

Heh.  This is what I was saying - Query is going to produce "SELECT x, y, z 
FROM (your custom statement) ORDER BY <order by>".    You blow away that SELECT 
on the outside you lose the ORDER BY also and anything else.    The only path 
here would involve a much more concerted effort with the overriding of the 
Select construct to pull off everything it does and apply it to the thing 
that's being wrapped.    Each new thing you'd like to do, like JOIN to it, 
etc., means your magic compiler would need to work it out.

The key issue here is that SQL Server doesn't supply a generically useful form 
of CTE since it cannot be nested.   Very uphill.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to