Omar Abdelrazik
Omar Abdelrazik

Reputation: 723

Python: How to use SQLALCHEMY to filter SQL object in array

I have a SQLAlchemy query in python where I want to filter output if a column value exists in a locally created array. However, this always returns None.

offices = ['US', 'UK', 'MEX']
users_db = models.s.query(models.User).filter(models.User.location in offices).all()

Is there a different implementation to that in SQLAlchemy or am I doing something wrong?

Upvotes: 0

Views: 398

Answers (1)

Ian Wilson
Ian Wilson

Reputation: 9039

Use in_ to create SQL IN clause.


models.s.query(models.User).filter(models.User.location.in_(offices)).all()

Upvotes: 1

Related Questions