假设表foo
具有复合主键(a,b)
,我如何使用SQLAlchemy (postgresql方言)生成以下sql查询?
SELECT * FROM foo WHERE (a,b) IN ((1,2), (2,3));
答案如下:
from sqlalchemy.sql.expression import Tuple
session.query(Foo).filter(Tuple(Foo.a, Foo.b).in_([(1,2), (3,4)])).all()