I am attempting to execute a SQL query within a Python script which will append a new month of data to an existing SQL table. When executing the query, I receive the below error:
ProgrammingError: ('The SQL contains 0 parameter markers, but 2 parameters were supplied', 'HY000')
I am running Python 3.11.8 and my SQL is in Hadoop. I have found several related posts but the solutions used in those don’t appear to be helping.
Below is the code I’m using to set my parameters as the previous month, establish the query, and execute with ?s used as my parameter markers.
# set connection
cnxn = pyodbc.connect("DSN=SDL", autocommit=True)
cursor = cnxn.cursor()
cursor.execute("SET tez.queue.name=hbi_llap;")
# set target month
today = datetime.date.today()
first = today.replace(day=1)
last_month = first - datetime.timedelta(days=1)
last_month = last_month.strftime("%Y%m")
print(last_month)
params = (last_month, last_month)
# load data
load_subs = '''
---INSERT INTO Table---
INSERT overwrite table cust_data.cust_zip_exp
PARTITION (date = ?)
SELECT location,
product_type,
zip_code,
SUM(amount) as cust_exp
FROM cust_data_source.cust_mth_data
WHERE date = ?
GROUP BY location,
proudct_type,
zip_code;
'''
# execute
cursor.execute(load_subs, params)
I’ve tried a few different ways of setting the parameter markers but they are each unrecognized. Please let me know if I can provide any further detail.