I am looking for some help with my Py code. It uploads to an Azure SQL using PYODBC MS 18.
When I insert I am using placeholders:
insert_sql ='''INSERT INTO table_name (ID, time, views, likes, shares, comments, URL)
VALUES (?, ?, ?, ?, ?, ?, ?)
#Issue line# ON DUPLICATE KEY UPDATE ID=current_data[0], time=current_data[1], views=current_data[2], likes=current_data[3], shares=current_data[4], comments=current_data[5], URL=current_data[6]
'''
insert_data=[(current_data[0], current_data[1], current_data[2], current_data[3], current_data[4], current_data[5], current_data[6])]
crsr.executemany(insert_sql, insert_data)
Objective - Insert into table, If the ID is already in the table, replace the row with the same data.
Only because I just want it to update the same keys when needed.
Error:
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Incorrect syntax near the keyword 'ON'. (156) (SQLExecute); [42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Statement(s) could not be prepared. (8180)")