Oladapo Adebowale
Oladapo Adebowale

Reputation: 59

Flask SQLAlchemy exist statement

This is my query

exist = db.session.query((exists().where(CreateUser.email == email) & (CreateUser.password == password))).scalar()

But I get this error:

sqlalchemy.orm.exc.MultipleResultsFound

My semantic is, it should check if the email and password exist from the table but I get this error.

What am I doing wrong?

Upvotes: 1

Views: 486

Answers (2)

r-m-n
r-m-n

Reputation: 15090

You need to put brackets around whereclause

exist = db.session.query((exists().where( (CreateUser.email == email) & (CreateUser.password == password) ))).scalar()

Upvotes: 1

Peter M. Elias
Peter M. Elias

Reputation: 1194

The exists() function returns a boolean. If you want to return a single row, just do this:

session.query(User).filter(User.email == email).filter(User.password == password).first()

Upvotes: 0

Related Questions