I'm trying to use the new CTE support in SQLAlchemy in a way that will
allow me to reference the recursion level as a field in the query
result.  This is easy in a straight SQL CTE by aliasing a constant in
the non-recursive part, and then referencing the alias in the
recursive part.  The limited example below (tested in PostgreSQL)
demonstrates this with a single field, and yields 0-10 inclusive:

WITH RECURSIVE cte AS (
    SELECT 0 as x
  UNION ALL
    SELECT cte.x + 1 FROM cte WHERE cte.x < 10
)
SELECT * from cte;

I can't figure out how to replicate this in SQLAlchemy, though.
Specifically, I'm stumped on how to represent the "0 as x" part in
SQLAlchemy.  How do you do it?  I've tried variations of this:

select("0").alias(name="x")

as column specs, but with no luck so far.

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