Re: [sqlalchemy] nested correlated exists subquery ?

2016-07-08 Thread Tim Chen
Thanks! It seems so much more intuitive after seeing an example. On Friday, July 8, 2016 at 11:51:49 AM UTC-4, Mike Bayer wrote: > > > > the basic idea (assuming ORM style) would be like: > > e = aliased(Engagement) > ee = aliased(Engagement) > > e1 = exists().where(and_( >ee.id ==

Re: [sqlalchemy] nested correlated exists subquery ?

2016-07-08 Thread Mike Bayer
the basic idea (assuming ORM style) would be like: e = aliased(Engagement) ee = aliased(Engagement) e1 = exists().where(and_( ee.id == 156, ee.target_id == e.target_id, ee.candidate_id == e.candidate_id )) e2 = exists().where(and_( Message.id == e.id, e1 )) q =

[sqlalchemy] nested correlated exists subquery ?

2016-07-08 Thread Tim Chen
Hi, I'm wondering what the correct syntax is for a nested correlated exists subquery? I have Message and Engagement declarative tables and here is the query i'm trying to replicate: select * from message m where exists ( select 1 from engagement e where m.engagement_id = e.id and exists