I have list of integer containing ids and a string variable. How can use these variables in an SQL statement? If I use this:
list_of_ids = [1,2,3]
s_date = '2015-01-01'
cursor.execute("""
SELECT * FROM foo WHERE id IN (%s)
AND start_date=%s
""", (list_of_ids,s_date))
The list_of_ids will be enclosed in quotes which shouldn't be.
This question is related to this imploding a list for use in a python MySQLDB IN clause but only the IN statement part.
I'm using psycopg2 connection -- in case that helps.