Was ist falsch mit der folgenden Aussage?MySQL Fehler mit Einfügen/Update auf Duplicate Key
Ich versuche, Daten in meine Tabelle einzufügen, aber es zu aktualisieren, wenn es ein doppelter Eintrag ist - wenn ich es laufen, bekomme ich folgende Fehlermeldung:
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'updat e temp set impressions = impressions + 1, clicks = clicks + 0, ctr = (ctr +' at line 1")
def insert_or_update_new(self, profile_id, landing_page, keyword, position, impressions, clicks, ctr):
try:
self.cursor.execute('''insert into temp (profile_id, landing_page, keyword, position, impressions, clicks, ctr) values (%s, %s, %s, %s, %s, %s, %s) on duplicate key update temp set impressions = impressions + %s, clicks = clicks + %s, ctr = (ctr + %s/2)''', (profile_id, landing_page, keyword, position, impressions, clicks, ctr, impressions, clicks, ctr))
self.db.commit()
except Exception as e:
self.db.rollback()
# Rollback in case there is any error
return e
Update: Entfernen doppelte UPDATE - Fehler immer noch da.
Sie haben dupliziertes 'update update'. – cwallenpoole