-
How would I go about setting up a query like this? ids = [1, 17, 202]
result = commands.query(
"""
SELECT * FROM template WHERE id IN ?ids?
""",
model=Template,
param={
'ids': ids
} Of course this won't work for Sqlite, because sqlite doesn't support list bindings. So I referred to this stack overflow thread: https://stackoverflow.com/questions/1309989/parameter-substitution-for-a-sqlite-in-clause And then tried to do this: ids = [1, 17, 202]
result = commands.query(
f"""
SELECT * FROM template WHERE id IN ({','.join('?'*len(ids))})
""",
model=Template,
param=ids
) Still no luck. What should I do here? |
Beta Was this translation helpful? Give feedback.
Answered by
arieroos
Feb 12, 2025
Replies: 1 comment 3 replies
-
Here is what I did: ids = [1, 17, 202]
param_names = [f'?id_{id}?' for id in ids]
result = commands.query(
f"""
SELECT * FROM template WHERE id IN ({','.join(param_names)})
""",
model=Template,
param={f'id_{id}': id for id in ids}
) This seems to work |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
arieroos
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is what I did:
This seems to work