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 don't want a scalar value 
(e.g. "thing"._in(myquery.as_scalar()) ), which kind of aligns with my 
theory that it just wraps stuff in parenthesis. Is that all it does, or 
does it do something more? It doesn't work on the top level query, but 
would it be safe to simply wrap all the nested queries with a 
(...).as_scalar()?

Thanks!
-Haoyi

On Tuesday, May 7, 2013 11:53:52 AM UTC-4, Michael Bayer wrote:
>
> 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 <haoy...@gmail.com <javascript:>> 
> wrote:
>
> I posted this 
> question<http://stackoverflow.com/questions/16410888/sqlalchemy-aliases-not-aliasing>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().cselect([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 xWHERE 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+...@googlegroups.com <javascript:>.
> To post to this group, send email to sqlal...@googlegroups.com<javascript:>
> .
> 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.


Reply via email to