Reputation: 59
I want to check if a row with two values for two columns exists. I tried the following code, but it only works for the first column, email, but not pass. How do I check both columns in the where
clause?
session.query(exists().where(User.email == '...' and User.pass == '...')).scalar()
Upvotes: 2
Views: 1276
Reputation: 127200
SQLAlchemy filter objects are combined with the bitwise operators &
and |
, not the boolean and
and or
.
session.query((exists().where(User.email == '...') & (User.password == '...'))).scalar()
There are also and_
and or_
functions to combine multiple statements.
import sqlalchemy as sa
sa.and_(User.email == '...', User.password == '...')
Upvotes: 1