I've committed a change in 5852 that will allow subquery() to be used  
in a scalar context in a WHERE clause - as_scalar() is now called on  
Alias objects.

On Mar 21, 2009, at 4:30 AM, Victor Lin wrote:

>
> Hi,
>
> I am using Elixir that based on SQLAlchemy to do some query like this:
>
> onAirs = db.session.query(model.OnAir.user_id).subquery()
> sites = db.session.query(model.Site).filter(model.Site.user_id.in_
> (onAirs))
>
> But it act not exactly like what I think. I got a syntax error:
>
> ProgrammingError: (ProgrammingError) (1064, "You have an error in your
> SQL syntax; check the manual that corresponds to your MySQL server
> version for the right syntax to use near 'SELECT on_air.user_id \nFROM
> on_air' at line 4") u'SELECT site.user_id AS site_user_id, site.title
> AS site_title, site.brief AS site_brief, site.description AS
> site_description, site.visited AS site_visited, site.listened AS
> site_listened, site.language AS site_language \nFROM site, (SELECT
> on_air.user_id AS user_id \nFROM on_air) AS anon_1 \nWHERE
> site.user_id = SELECT on_air.user_id \nFROM on_air' []
>
> Well... it obviously, there is lack of parentheses. If I rewrite the
> query syntax with parentheses, everything works fine.
>
> SELECT site.user_id AS site_user_id, site.title AS site_title,
> site.brief AS site_brief, site.description AS site_description,
> site.visited AS site_visited, site.listened AS site_listened,
> site.language AS site_language \nFROM site, (SELECT on_air.user_id AS
> user_id \nFROM on_air) AS anon_1 \nWHERE site.user_id = (SELECT
> on_air.user_id \nFROM on_air)
>
> It does'nt make sense why SQLAlchemy did't put parentheses around
> subquery? Is that a bug? What should I do to solve this problem?
>
> Thanks.
> Victor Lin.
> >


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