次の文は何が問題になりますか?重複キーの挿入/更新でMySQLエラーが発生しました
私は私のテーブルにデータを挿入するが、重複したエントリがある場合はそれを更新しようとしている - 私はそれを実行すると、私は次のエラーを取得:
(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を - まだそこにはエラーがあります。
を好きではないはずです:-)トリックを行う可能性があります削除し、二回単語更新を含み更新版の更新版を複製しました。 – cwallenpoole