Repository navigation
Replies: 1 comment
|
Use from sqlmodel import col, select
statement = select(Hero).where(col(Hero.dead).is_(False))
heroes = session.exec(statement).all()With your sample data, this returns Spiderman. For the other cases: col(Hero.dead).is_(True) # Batman
col(Hero.dead).is_(None) # Superman
Also, The SQLModel docs explain |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Code
Description
I am wondering what the correct syntax to use for where clauses on booleans is. I found two syntaxes that work, but both have lint errors. And two other syntaxes that seem correct but do not give the desired result.
.where(Hero.dead == False)Avoid equality comparisons toFalse; usenot Hero.dead:for false checks"where(Hero.dead.is_(False))Cannot access attribute "is_" for class "bool" Attribute "is_" is unknown.Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.24
Python Version
Python 3.13.2
Additional Context
No response
All reactions