[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Michael Bayer


col.in_(select([MyClass.col2]))

Mike Conley wrote:
> On Wed, Mar 18, 2009 at 11:00 AM, Michael Bayer
> wrote:
>
>>
>> Sanjay wrote:
>> >
>> > Hi,
>> >
>> > I want to write something like
>> >
>> > query.filter(BizObj.col.in_("SELECT col FROM some_table")).
>> >
>> > Could not find out how to do it. The code on neither the above nor the
>> > below worked.
>> >
>> > query.filter(BizObj.col1.in_(sqlalchemy.sql.text("SELECT col1 FROM
>> > sometable"))).
>>
>>
>> in_() is going to want a select() construct for that calling style.  if
>> you don't have a Table or mapped class for "sometable", you can make an
>> ad-hoc table using table():
>>
>> from sqlalchemy.sql import table, column
>>
>> BizObj.col1.in_(select([table("sometable", column("col1")).c.col1]))
>>
>>
> and if I do have a mapped class, say SomeClass, is there an ORM-like
> syntax
> to use  the class or do I drop into SQL-like syntax using
> SomeClass.__table__ ?
>
> query = session.query(BizObj).filter(BizObj.col1.in_(??))
>
> >
>


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



[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Mike Conley
On Wed, Mar 18, 2009 at 11:00 AM, Michael Bayer wrote:

>
> Sanjay wrote:
> >
> > Hi,
> >
> > I want to write something like
> >
> > query.filter(BizObj.col.in_("SELECT col FROM some_table")).
> >
> > Could not find out how to do it. The code on neither the above nor the
> > below worked.
> >
> > query.filter(BizObj.col1.in_(sqlalchemy.sql.text("SELECT col1 FROM
> > sometable"))).
>
>
> in_() is going to want a select() construct for that calling style.  if
> you don't have a Table or mapped class for "sometable", you can make an
> ad-hoc table using table():
>
> from sqlalchemy.sql import table, column
>
> BizObj.col1.in_(select([table("sometable", column("col1")).c.col1]))
>
>
and if I do have a mapped class, say SomeClass, is there an ORM-like syntax
to use  the class or do I drop into SQL-like syntax using
SomeClass.__table__ ?

query = session.query(BizObj).filter(BizObj.col1.in_(??))

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



[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Michael Bayer

Sanjay wrote:
>
> Hi,
>
> I want to write something like
>
> query.filter(BizObj.col.in_("SELECT col FROM some_table")).
>
> Could not find out how to do it. The code on neither the above nor the
> below worked.
>
> query.filter(BizObj.col1.in_(sqlalchemy.sql.text("SELECT col1 FROM
> sometable"))).


in_() is going to want a select() construct for that calling style.  if
you don't have a Table or mapped class for "sometable", you can make an
ad-hoc table using table():

from sqlalchemy.sql import table, column

BizObj.col1.in_(select([table("sometable", column("col1")).c.col1]))


>
> Needing help.
>
> thanks,
> Sanjay
> >
>


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



[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Glauco

Sanjay ha scritto:
> I got that the obvious way is just writing the string query, i.e.
>
> query.filter("col IN SELECT col FROM some_table")
>
>   
something like this:

query.filter( col.in_( select([col],...).correlate(None) ))



Glauco




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



[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Sanjay

I got that the obvious way is just writing the string query, i.e.

query.filter("col IN SELECT col FROM some_table")

Still a bit curious to know whether there a way using BizObj.col.in_

thanks,
Sanjay

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