[sqlalchemy] Newbie Question: Aliases not Aliasing?

2013-05-07 Thread Haoyi Li
I posted this questionhttp://stackoverflow.com/questions/16410888/sqlalchemy-aliases-not-aliasingto StackOverflow, but thought this may be a better place to ask. I have the following sqlalchemy code: x = bbc.alias().c w = bbc.alias().cselect([func.distinct(x.region)]).where(

Re: [sqlalchemy] Newbie Question: Aliases not Aliasing?

2013-05-07 Thread Michael Bayer
update the SO question too for me...in this case it needs a clue to interpret the select as a scalar: subq = select([func.sum(w.population)]).where((w.region == x.region)) print select([func.distinct(x.region)]).where(subq.as_scalar() 1) the WHERE 1 you're getting is because

Re: [sqlalchemy] Newbie Question: Aliases not Aliasing?

2013-05-07 Thread Haoyi Li
Thanks, that worked! A follow up question to make sure i'm understanding this right: I'm looking at the effect of .as_scalar() on the query, and it seems that any query I call .as_scalar() on simply gets wrapped in parenthesis. I tested it out and it seems that it works even in cases where I

Re: [sqlalchemy] Newbie Question: Aliases not Aliasing?

2013-05-07 Thread Michael Bayer
it's a Python thing, it turns the FromClause into a ColumnElement which then has operators like __eq__(), __lt__(), etc. On May 7, 2013, at 2:29 PM, Haoyi Li haoyi...@gmail.com wrote: Thanks, that worked! A follow up question to make sure i'm understanding this right: I'm looking at the