[sqlalchemy] [Q] Struggle with exists

2013-03-01 Thread Ladislav Lenart
Hello. I don't know how to write the following query in SA (using constructs such as query, select, exists): SELECT EXISTS( SELECT 1 FROM imported_client_share JOIN imported_partner_share ON imported_client_share.deal_id = imported_partner_share.deal_id JOIN deal

Re: [sqlalchemy] [Q] Struggle with exists

2013-03-01 Thread Michael Bayer
we should probably add a method to Query called exists() that just turns any query into EXISTS (SELECT 1), here's how to make it work for now from sqlalchemy import exists q1 = session.query(ImportedClientShare) q1 = q1.join(ImportedPartnerShare, ImportedClientShare.deal_id

Re: [sqlalchemy] [Q] Struggle with exists

2013-03-01 Thread Ladislav Lenart
Thank you! I was missing the following bit(s): q = session.query( exists(q1.with_entities('1').statement) | exists(q2.with_entities('1').statement) ) I knew about Query.statement but I did not figure out how to combine that with OR. It did not occur to me that I can