I have a case where I am generating a query during the parsing of an
expression.
It behooves me to use generative subquery as a way of generating some
complex
sql expressions. For example: in the following nested table
structure
atable = Table ('atable', metadata,
Column('id', Integer, primary_key=True),
Column('name', String)
)
btable = Table ('btable', metadata,
Column('id', Integer, primary_key=True)
Column('parent_id', Integer, ForeignKey('atable.id')))
Column('value', String)
)
ctable = Table ('ctable', metadata,
Column('id', Integer, primary_key=True)
Column('parent_id', Integer, ForeignKey('btable.id')))
)
class A:
pass
class B:
pass
class C:
pass
mapper(A, atable)
mapper(B, btable)
mapper(C, ctable)
##
The parser will see expressions for A first, B, and then C,
I would like to do something like the following in sequence but not
necessarily at the same time.
q = session.query(A).filter (A.name == 'boo')
q = session.query(B).filter (B.parent_id == q && B.value == 1)
q = session.query (C).filter (C.parent_id == q)
which would generate something like:
select id from ctable where ctable.parent_id in
( select id from btable where btable.value =1 and
btable.parent_id in
( select id from atable where atable.name = 'boo'))
##
I have tried several incantations, but have not been to get it right..
Any ideas?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---