I have the following code:
query = "SELECT * FROM appointments WHERE service IN %s AND location LIKE '%London%'"
values = (services,) # services is a tuple of strings.
cur.execute(query, values)
When I execute this code I get the following error:
--> cur.execute(query, values)
IndexError: tuple index out of range
After researching the topic a little bit, I think that the %L
in the query is being detected as a placeholder, so the psycopg2
library is trying to insert data there, but there is no more data in the values
tuple.
I have tried escaping the %
sign using the following query:
query = "SELECT * FROM appointments WHERE service IN %s AND location LIKE '%%London%'"
but this has also not worked.
How can I fix this issue and get the expected behaviour?