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() > 100000000) the "WHERE 1" you're getting is because "someselect > 10000" just comes out to Python True. On May 7, 2013, at 9:58 AM, Haoyi Li <haoyi...@gmail.com> wrote: > I posted this question to StackOverflow, but thought this may be a better > place to ask. > > I have the following sqlalchemy code: > > x = bbc.alias().c > w = bbc.alias().c > select([func.distinct(x.region)]).where( > select([func.sum(w.population)]).where((w.region == x.region)) > 100000000 > ) > I would expect it to produce this SQL: > > SELECT DISTINCT(x.region) > FROM bbc x > WHERE 100000000 < ( > SELECT SUM(w.population) > from bbc w > WHERE w.region = x.region > ) > but instead it gives me this: > > SELECT distinct(bbc_1.region) AS distinct_1 > FROM bbc AS bbc_1 > WHERE 1 > Somehow the WHERE clause is collapsing, but for the life of me I can't see > why. Am I doing something wrong with the aliases? > > -- > 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 sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.