5 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: subquery with orm va...| From | Sent On | Attachments |
|---|---|---|
| kris | 27 Nov 2007 17:18 | |
| Michael Bayer | 27 Nov 2007 20:32 | |
| kris | 27 Nov 2007 20:51 | |
| Michael Bayer | 27 Nov 2007 20:56 | |
| kris | 27 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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqla...@googlegroups.com
To unsubscribe from this group, send email to
sqla...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---




