Madhura Pawar
Madhura Pawar

Reputation: 13

pyodbc parameterized insert for Impala ODBC Driver

I am attempting to do parameterized insert query using pyodbc and Cloudera ODBC Driver for Impala but it is not working. I am trying to execute the following query.

   import pyodbc
   insert_query = "insert into table_name(id,name,price) values(?,?,?)"
   cursor.execute(insert_query,1,"Apples","20 dollars")

Here is the error I receive:

The SQL contains 0 parameter markers but 3 parameters were supplied, 'HY000'

If I execute the query using Python formatting like this it WORKS:

query_format = "insert into table_name(id,name,price) values({},\"{}\",\"{}\")".format(1,"Apples","20 dollars")
cursor.execute(query_format)

But I really want to specify parameters separately because I would want to do cursor.executemany() to do batch inserts later on and using the formatting approach forces me to use for loop.

Instead of sending values separately , I used tuple too , a list too. Nothing works. Why is it not recognizing "?" as a parameter marker?

Python - 3.7.4, Pyodbc - 4.0.27, Anaconda - 1.7.2, OS - Windows 10

Upvotes: 1

Views: 1112

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123409

As resolved on GitHub here, this is an issue with the ODBC driver in question, not a problem with pyodbc.

Upvotes: 0

Related Questions