I've been trying to test various methods for making my code to run. To begin with, I have this list:
member_list = [111,222,333,444,555,...]
I tried to pass it into this query:
query = pd.read_sql_query(
"""
select member id
,yearmonth
from queried_table
where yearmonth between ? and ?
and member_id in ?
""", db2conn, params = [201601, 201603, member_list])
However, I get an error that says:
'Invalid parameter type. param-index=2 param-type=list', 'HY105'
So I looked around and tried using formatted strings:
query = pd.read_sql_query(
"""
select member id
,yearmonth
from queried_table
where yearmonth between ? and ?
and member_id in (%s)
""" % ','.join(['?']*len(member_list), db2conn, params = [201601, 201603, tuple(member_list)])
Now, I get the error:
'The SQL contains 18622 parameter markers, but 3 parameters were supplied', 'HY000'
because it's looking to fill in all the ?
placeholders in the formatted string.
So, ultimately, is there a way to somehow evaluate the list and pass each individual element to bind to the ?
or is there another method I could use to get this to work?
Btw, I'm using pyodbc
as my connector.
Thanks in advance!