Bitwise operator in SQLAlchemy

后端 未结 1 1711
情歌与酒
情歌与酒 2020-12-30 06:30

How would I write the following SQL query in SQLAlchemy involving a bitwise and?

select * from table where flags &         


        
相关标签:
1条回答
  • 2020-12-30 06:50

    You want to use the bitwise operator like this:

    session.query(User).filter(somecolumn.op('&')(1) == 1)
    

    You can write something similar for OR:

    session.query(User).filter(somecolumn.op('|')(4) > 4)
    
    0 讨论(0)
提交回复
热议问题