Thanks again Michael. The syntax was just made up pseudo code. I was in a hurry to respond.
Anyway, this worked and here's a snippet of what it looks like: sharedFilterQuery = '''WITH RECURSIVE q AS ( SELECT h.* FROM "Selection"."FilterFolder" h join "Selection"."Filter" f on f."filterFolderId" = h.id WHERE f.id = :filterId UNION SELECT hp.* FROM q JOIN "Selection"."FilterFolder" hp ON hp.id = q."parentFolderId" ) SELECT f.id FROM "Selection"."Filter" f where f.id = :filterId and (f."createdByUserId" = 1 or exists(select 1 from q where "isShared" = TRUE LIMIT 1)) ''' inClause = text(sharedFilterQuery,bindparams=[bindparam('filterId',filterId)]) f = session.query(Filter).filter(Filter.description == None)\ .filter(Filter.id.in_(inClause)).first() -- 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.