Re: [sqlalchemy] How to make a SQLAlchemy query using exists with a correlated subquery containing joins?

2013-08-08 Thread Etienne Rouxel
Hello I tried the use of where(e) but it fires the following error: AttributeError: 'Query' object has no attribute 'where' I tried with filter(e) instead and the query does not fire any error but the result is not exactly what is expected. Here is the query: e = session.query(Plant).\

Re: [sqlalchemy] How to make a SQLAlchemy query using exists with a correlated subquery containing joins?

2013-08-08 Thread Etienne Rouxel
I have managed to add the missing SQL part with the following query: e = session.query(Plant).\ join(Article, Plant.articles).\ join(Catalogitem, Article.catalogitems).\ filter( Catalogitem.marketingseason == marketingseason, Plant.taxon_id == Taxon.id ).\

Re: [sqlalchemy] How to make a SQLAlchemy query using exists with a correlated subquery containing joins?

2013-08-08 Thread Ladislav Lenart
Hello. This is the correct solution. I think you HAVE to specify the correlation between the exists() subquery and the main query. But I am no SA expert. I would suggest to add id (a sequence) as your primary key and use it as FK everywhere. You can turn the current composite primary key into a

Re: [sqlalchemy] How to make a SQLAlchemy query using exists with a correlated subquery containing joins?

2013-08-08 Thread Michael Bayer
On Aug 8, 2013, at 2:02 AM, Etienne Rouxel rouxel.etie...@gmail.com wrote: Hello I tried the use of where(e) but it fires the following error: AttributeError: 'Query' object has no attribute 'where' sorry, I meant filter() I tried with filter(e) instead and the query does not fire any

Re: [sqlalchemy] How to make a SQLAlchemy query using exists with a correlated subquery containing joins?

2013-08-08 Thread Etienne Rouxel
Ok, thank you very much, one more time! And thank you to Ladislav Lenart as well. Le jeudi 8 août 2013 15:33:58 UTC+2, Michael Bayer a écrit : On Aug 8, 2013, at 2:02 AM, Etienne Rouxel rouxel@gmail.comjavascript: wrote: Hello I tried the use of where(e) but it fires the following

[sqlalchemy] How to make a SQLAlchemy query using exists with a correlated subquery containing joins?

2013-08-07 Thread Etienne Rouxel
Hello Long story cut short, I would like to know if it is possible to generate a query with SQLAlchemy ORM such as the one below and how. SELECT botany.taxon.id AS botany_taxon_id FROM botany.taxon WHERE EXISTS (SELECT 1 FROM botany.plant JOIN product.article ON

Re: [sqlalchemy] How to make a SQLAlchemy query using exists with a correlated subquery containing joins?

2013-08-07 Thread Michael Bayer
On Aug 7, 2013, at 11:58 AM, Etienne Rouxel rouxel.etie...@gmail.com wrote: Hello Long story cut short, I would like to know if it is possible to generate a query with SQLAlchemy ORM such as the one below and how. SELECT botany.taxon.id AS botany_taxon_id FROM botany.taxon