How to construct a slightly more complex filter using “or_” or “and_” in SQLAlchemy

前端 未结 4 941
北海茫月
北海茫月 2020-12-25 12:16

I\'m trying to do a very simple search from a list of terms

terms = [\'term1\', \'term2\', \'term3\']

How do I programmatically go through

4条回答
  •  臣服心动
    2020-12-25 12:37

    I had the same issue in"SQLAlchemy: an efficient/better select by primary keys?":

    terms = ['one', 'two', 'three']
    clauses = or_( * [Table.field == x for x in terms] )
    query = Session.query(Table).filter(clauses)
    

提交回复
热议问题