How to use the "IN" clause using the select statement #1475
-
| First Check
 Commit to Help
 Example Code# Something similar to this from sqlalchemy
session.execute(
    select(
        [MyUserTable.c.id, MyUserTable.c.name], 
        MyUserTable.c.id.in_((123, 456))
    )
).fetchall()DescriptionTrying to use the "IN" clause in the sqlmodel, where I could filter out based on a list of values Operating SystemLinux Operating System DetailsNo response SQLModel Version0.0.6 Python Version3.10.4 Additional ContextNo response | 
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
| Hi, try this way:         db_setting = session.exec(select(Settings).where(Settings.id.in_([1,2,3]))).all()UPD YuriiMotov:         db_setting = session.exec(select(Settings).where(col(Settings.id).in_([1,2,3]))).all() | 
Beta Was this translation helpful? Give feedback.
-
| Thanks, @mgurg, this works. Weirdly enough,  | 
Beta Was this translation helpful? Give feedback.
-
| try https://sqlmodel.tiangolo.com/tutorial/where/#type-annotations-and-errors from sqlmodel import col
col(Settings.id).in_([1,2,3]) | 
Beta Was this translation helpful? Give feedback.
-
| I read the whole documentation and don't know how I could have missed this. Thank you, @hrehfeld! | 
Beta Was this translation helpful? Give feedback.
Hi, try this way:
UPD YuriiMotov:
Use
colas @hrehfeld showed to get atocompletions.