I am working on being able to pass date parameters into my SQL queries I am running in Python. The parameters work for for my regular SQL queries but are not working for my Hive SQL queries and I am not sure why? I am getting a "The SQL contains 0 parameter markers, but 1 parameters were supplied" error but only for Hive SQL. This code runs as intended:
conn_sql = pyodbc.connect(f"DRIVER{{NetezzaSQL}};SERVER=server1;PORT=xxxx;DATABASE=SYSTEM;UID=xxxxxx;PWD=xxxxxx;")
# Define Cursor
cus_sql=conn_sql.cursor()
conn_hadoop = pyodbc.connect("DSN=Hive_Connection", autocommit=True)
start_date = input("Enter start date: ")
end_date = input("Enter end date: ")
sql = """SELECT user_id
FROM table
WHERE DATE_TIME >= CAST(? AS varchar(25)) AND a.DATE_TIME < CAST(? AS varchar(25))"""
df = pd.read_sql(sql,conn_sql,params=[start_date,end_date])
The below code throws the 0 param error.
with pyodbc.connect("DSN=Hive_Connection", autocommit=True) as conn_hadoop:
df = pd.read_sql("""SELECT user_id
FROM table
WHERE date_time >= ? and date_time < end_time
""",conn_hadoop,params=[start_time,end_time])
I cannot figure out what is causing that. Do I need a different format for parameter passing for a Hive connection? I didn't see anything on that in my search but maybe I missed it.