Ricardo Ricardo - 1 year ago 118
MySQL Question

filter with more than one value on flask-sqlalchemy

I want a query with multiple value like

where id in (3,4,5)

Then I have a
my_list = [3,4,5]
so how can I pass that list as an argument to filter in sqlalchemy?

query = Notification.query.filter_by(id=my_list).all()

Answer Source

Use in_ with filter:

query = Notification.query.filter(Notification.id.in_(my_list)).all()

Here's the relevant SO Q&A, and Read the Doc from sqlalchemy

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download