I am working on using python to upload JSON data to MySQL. I need to include "ON DUPLICATE KEY UPDATE VALUES" in the insert statement, but am running into issues in Python.
If I run the following code, everything works...
import json
import mysql.connector
mydb = mysql.connector.connect(host=x,user=x,password=x,database=x)
cursor = mydb.cursor()
json_data = json.loads(file)
for item in json_data['data']:
cursor.execute(
"INSERT INTO input_1 (a,b,c,d) VALUES (%s,%s,%s,%s)",
(item['a'],item['b'],item['c'],item['d'])
)
However, when I tack on the "ON DUPLICATE KEY" to the end...
import json
import mysql.connector
mydb = mysql.connector.connect(host=x,user=x,password=x,database=x)
cursor = mydb.cursor()
json_data = json.loads(file)
for item in json_data['data']:
cursor.execute(
"INSERT INTO input_1 (a,b,c,d) VALUES (%s,%s,%s,%s) ON DUPLICATE KEY UPDATE VALUES a=%s,b=%s,c=%s",
(item['a'],item['b'],item['c'],item['d'])
)
I Get the Following Message:
ProgrammingError: Not enough parameters for the SQL statement