On Nov 26, 2013, at 7:45 AM, Joseph Casale <jcas...@gmail.com> wrote:
> I have a scalar sub query with a predicate that involves a table and column > produced in the > outer query, Company.id for example. this is called a correlated subquery. > The only way I could include the query was to write > it out literally and add it as a column with literal_column. > > query = session.query(Company, City, <...>, literal_column(sub)).\ > join(City).\ > join(<...>).\ > filter(<...>) > ... > > I have the sub query written using the actual table classes etc, but could > not find a way to > include the non text representation of the sql statement (sub) into the outer > query. you build up your subquery normally, then you can inject it as a column using as_scalar(), some background is at http://docs.sqlalchemy.org/en/rel_0_9/core/tutorial.html#scalar-selects
signature.asc
Description: Message signed with OpenPGP using GPGMail