On Mon, Jul 09, 2012 at 03:12:16PM -0700, Russ wrote:
> 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")
select(literal(0).alias("x")) should do it, see the documentation at
http://docs.sqlalchemy.org/en/rel_0_7/core/expression_api.html#sqlalchemy.sql.expression.literal

> 
> as column specs, but with no luck so far.
> 

-Ryan Kelly

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