Skip to content

Binding single variable and list of variables in the same statement #103

Closed Answered by anthony-tuininga
urosdigital asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you cannot bind an array with cursor.execute(). You could simply do this:

cursor.execute(query, ids)

But better yet would be to do this:

bind_names = ",".join(":" + str(i + 2) for i in range(len(ids)))
bind_values = [element] + ids
query= f"select * from table where element = :1 and id in ({bind_names})"
cursor.execute(query, bind_values)

That way you are using bind variables for everything.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@urosdigital
Comment options

Answer selected by urosdigital
Comment options

You must be logged in to vote
1 reply
@urosdigital
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants