Assuming a table foo
with compound primary key (a,b)
, How I can generate following sql query with SQLAlchemy (postgresql dialect)?
SELECT * FROM foo WHERE (a,b) IN ((1,2), (2,3));
Assuming a table foo
with compound primary key (a,b)
, How I can generate following sql query with SQLAlchemy (postgresql dialect)?
SELECT * FROM foo WHERE (a,b) IN ((1,2), (2,3));
Here is the answer:
from sqlalchemy.sql.expression import Tuple
session.query(Foo).filter(Tuple(Foo.a, Foo.b).in_([(1,2), (3,4)])).all()
© 2022 - 2024 — McMap. All rights reserved.