Python supports coordinated comparisons : 1 < 2 < 3 translates to (1 < 2) and (2 < 3) .
I am trying to make a SQL query using SQLAlchemy, which looks like this:
results = session.query(Couple).filter(10 < Couple.NumOfResults < 20).all()
The results obtained by me were not so expected. I turned on the echo=True keyword for the engine, and indeed - the generated SQL query included only one of two comparisons.
I cannot find documentation that explicitly states that this is prohibited. I suggested that if this type of expression is supported in Python, it should also be supported in SQLAlchemy.
Why is this not working? I have one possible solution (common in the answers), but we will be glad to hear other opinions.
Lior source share