I am trying to query a table with WHERE IN condition using mysql-connector-python like this:
JavaScript
x
3
1
ids = (12, 31)
2
cursor.execute("SELECT object_name FROM object_table WHERE object_id IN %s", ids)
3
And I get the following error:
JavaScript
1
2
1
mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
2
How can I get it working?
Advertisement
Answer
You should add “” in ids to be a String and also ‘,’ should be replaced with ‘%’
E.g.
JavaScript
1
3
1
ids = "(12, 31)"
2
cursor.execute("SELECT object_name FROM object_table WHERE object_id IN %s" % ids)
3