How to use the "IN" clause using the select statement #1475
Answered
by
mgurg
Praveenstein
asked this question in
Questions
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 |
Answered by
mgurg
May 31, 2022
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() |
0 replies
Answer selected by
YuriiMotov
|
Thanks, @mgurg, this works. Weirdly enough, |
0 replies
|
try https://sqlmodel.tiangolo.com/tutorial/where/#type-annotations-and-errors from sqlmodel import col
col(Settings.id).in_([1,2,3]) |
0 replies
|
I read the whole documentation and don't know how I could have missed this. Thank you, @hrehfeld! |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, try this way:
UPD YuriiMotov:
Use
colas @hrehfeld showed to get atocompletions.