Rodney wrote:
>
> In Oracle, I can write a query like this:
> SELECT ...
> FROM ...
> WHERE id IN (SELECT f_id FROM f ('param'))
> to constrain the returned rows to those that have an id in the set
> returned by the table function f.
>
> I would like to generate such a query with sqlalchemy like this:
> q = session.query (...)....filter (id.in_ (sq))
> but I cannot figure out how to define sq.
>
> I've tried something like this:
> sq = session.query ('F_ID').from_statement ('SELECT column_value FROM
> TABLE (f (:p1))').params(p1 = 'param')
> but I get:
> TypeError: 'Annotated_TextClause' object is not iterable
>
> Any suggestions?

not getting that error:

>>> from sqlalchemy.orm import create_session
>>> s = create_session()
>>> q = s.query ('F_ID').from_statement ('SELECT column_value FROM TABLE
(f (:p1))').params(p1 = 'param')
>>> print q
SELECT column_value FROM TABLE (f (:p1))

although the "subquery" you're trying to do here, if you intend to stay as
a straight string, I would just render as is within
Session.execute("select * from (select x, y, z from ...)").  Query doesn't
really have the fluency with completely textual expressions you're looking
for here.





>
> Thanks.
>
> Rodney
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to