I am trying to query a table with WHERE IN condition using mysql-connector-python like this:
ids = (12, 31)
cursor.execute("SELECT object_name FROM object_table WHERE object_id IN %s", ids)
And I get the following error:
mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
How can I get it working?
You should add "" in ids to be a String and also ',' should be replaced with '%'
Eg
ids = "(12, 31)"
cursor.execute("SELECT object_name FROM object_table WHERE object_id IN %s" % ids)
A query should be in the string format so you need to wrap your variable ids = (12, 31)
into a string like ids = "(12, 31)"
and also don't forget the add %
instead of ,
as you're passing some value.
ids = "(12, 31)"
cursor.execute("SELECT object_name FROM object_table WHERE object_id IN %s" % ids)
old answer but might be helpful for someone
this is what I did and it might be helpful here if ids is a list.
query = "UPDATE tableName SET lspaasStatus = 1 WHERE CompletedQuizId IN " + "("+str(updatedQuizids)[1:-1]+")"
mycursor.execute(query)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.