Sqlalchemy complex in_ clause with tuple in list of tuples

后端 未结 3 608
梦如初夏
梦如初夏 2020-12-08 17:43

I\'m trying to find a way to cause SQLAlchemy to generate a query of the following form:

select * from t where (a,b) in ((a1,b1),(a2,b2));

Is this poss

3条回答
  •  半阙折子戏
    2020-12-08 18:15

    Use tuple_:

    keys = [(a1, b1), (a2, b2)]
    session.query(T).filter(tuple_(T.a, T.b).in_(keys)).all()
    

    http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.tuple_

提交回复
热议问题