1

My code:

cursor.execute("select * from PRODUCT where product_id in (?)", (ids,))
print(cursor.fetchall())

where ids is a tuple of integer values like (2,4) and product_id are also integer values.

The error I'm getting is:

File "c:/Users/deboparna/Desktop/college/Sem4/programming language/project/db.py", line 32, in fetchProducts cursor.execute("select * from PRODUCT where product_id in (?)", (ids,)) sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

1
  • Please provide the entire error message, as well as a minimal reproducible example. Commented Mar 16, 2020 at 14:30

1 Answer 1

1

You need placeholders for each id.
You also should just use ids as a tuple, and not make it a tuple of a tuple.

placeholders = ",".join("?"*len(ids))
qry = "select * from product where product_id in ({})".format(placeholders)
cursor.execute(qry,ids)
Sign up to request clarification or add additional context in comments.

2 Comments

thank you! it worked. but I'm still unclear on why it worked. placeholders will just give a string of comma separated question marks. which we put in the query using format. How is it different from what I was doing. was i not doing the same but put the '?' directly instead of making it a variable?
Yes, but you were only putting one question mark when you needed two. And any way dynamically generating placeholders is easier when your ids variable can presumably change :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.