Reputation: 521
I am using python and sqlalchemy and want to perform a query with filters, using filter_rule
.
I have these DB records:
{"name":"xyz","age":40,"location":"ABC","salary":10000}
And I would like to make a query like this:
select * from my_table where age<50 and salary>8000;
I understand that I can use filter_rule="model.age < 50 and model.salary > 8000"
but it doesn't seem to work properly for me with the greater than and less than symbols.
However, the filter_rule
works perfectly fine if I have equality conditions like age==50
and salary==10000
.
Could someone explain this?
Upvotes: 2
Views: 5271
Reputation: 1761
from sqlalchemy import and_
filter_rule = and_(model.age<50, model.salary>8000)
Upvotes: 3