5 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: subquery with orm va...
FromSent OnAttachments
kris27 Nov 2007 17:18 
Michael Bayer27 Nov 2007 20:32 
kris27 Nov 2007 20:51 
Michael Bayer27 Nov 2007 20:56 
kris27 Nov 2007 21:55 
Subject:[sqlalchemy] Re: subquery with orm values
From:Michael Bayer (mike@zzzcomputing.com)
Date:11/27/2007 08:56:52 PM
List:com.googlegroups.sqlalchemy

On Nov 27, 2007, at 11:51 PM, kris wrote:

I tried

names.select (exists ([names.c.id], and_(names.c.id == obj_tags.c.name_id, obj_tags.c.parent_id==Taggable.c.id , Taggable.c.id == query.compile() ) however, I am getting too many fields back with the error "subquery must return only one column"

Any suggestion on how to ask for only the id column?

oh, well yeah now it will get slightly more tricky. you can pull out the "WHERE" criterion by itself using query._criterion, but that wont give you the joins anything else, i.e.

select([mytable.c.somecolumn], query._criterion).as_scalar()

if you have joins in there as well, you can get them like:

select([mytable.c.somecolumn], query._criterion, from_obj=query._from_obj).as_scalar()

im not sure at the moment how/if this particular kind of operation would be a regular query method....maybe query.generate_select() or something.. also as_scalar() wraps the select in a "scalar-holding" object that makes it act like a single column in expressions. its not entirely needed but can be helpful.