I have an issue with updating an existing table on the database with a pandas dataframe of values with multiple columns, but I only wanted to update the database with some of those columns, based on conditions of other columns.
An example:
import pandas as pd
import cx_Oracle
d = {'a': ['first', 'second'], 'b': [3, 4], 'c': ['2021-01-01', '2021-01-02'], 'd':[1.1,2.2], 'e':[5,6] }
df = pd.DataFrame(data=d)
#Update to the database
data = list(df.itertuples(index=False, name=None))
DBCONN = cx_Oracle.connect(db_username,db_password,dsn)
conn = DBCONN
cursor = conn.cursor()
query_add_data = """UPDATE my_table SET d = :d, c = :c WHERE a = :a AND b = :b"""
#updating the rows
cursor.executemany(query_add_data, data)
conn.commit()
I got the following error:
DatabaseError: ORA-01036: illegal variable name/number
Any ideas what I am doing wrong?