I have a method that inserts into table NKP
:
def insert_nkp(self, kniha):
query = """
INSERT INTO NKP SET
id_product = %s,
supplier_reference = %s,
nazev = %s,
nazev_orig = %s,
hlavni_zahlavi = %s,
preklad_z = %s,
zanr = %s,
nakladatel = %s,
vydani = %s,
rozsah = %s
"""
self.cursor.execute(query, kniha)
self.connection.commit()
But I want to insert into NKP
only if there is not existing the same id_product
. I tried to add
ON DUPLICATE KEY UPDATE
id_product = VALUES(id_product)
but it did not help. What is the most elegant way how to do this, please?