this issue goes to 0.7.9 and is a regression caused by 
http://www.sqlalchemy.org/trac/changeset/878af426f7eb19c257f1db83f5b1af34624c2c6a
 .   I'll have to look into it.


On Aug 13, 2013, at 9:07 PM, jtruscott <[email protected]> wrote:

> Hi,
> 
> I updated sqlalchemy from 0.7.8 to 0.8.2 and one of my queries started 
> failing. I had a CTE expression with capital letters in it's name, and in 0.8 
> it wasn't getting consistently quoted, but it worked in 0.7.
> 
> I narrowed it down, and it only seems to happen in a query containing 
> multiple subqueries referring to the same CTE. 
> 
> Here's an example that reproduces it. If I remove the second subquery from 
> this example, there's no issues:
> 
> import sys
> import sqlalchemy as sa
> import sqlalchemy.orm
> import psycopg2
> 
> engine = sa.create_engine('postgresql://', creator=lambda: 
> psycopg2.connect(dbname=sys.argv[1]), echo=True)
> Session = sa.orm.scoped_session(sa.orm.sessionmaker(bind=engine))
> session = Session()
> 
> cte = session.query(sa.literal(1).label("id")).cte(name='CTE')
> 
> firstSubquery = session.query(cte.c.id).subquery()
> secondSubquery = session.query(cte.c.id).subquery()
> 
> query = session.query(firstSubquery, secondSubquery)
> 
> print query.all()
> 
> 
> The resulting query looks like this. Note that the last reference to "CTE" is 
> not quoted like the others, causing a ProgrammingError when it can't be found.
> 
> WITH "CTE" AS
> (SELECT :param_1 AS id)
>  SELECT anon_1.id AS anon_1_id, anon_2.id AS anon_2_id
> FROM (SELECT "CTE".id AS id
> FROM "CTE") AS anon_1, (SELECT "CTE".id AS id
> FROM CTE) AS anon_2
> 
> Thanks,
> Jesse
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to