How to On Duplicate Key Update

mchruss03

I have this query that is executed in my Python script but when its inserting into the database and finds a duplicate of my unique column it causes it to error and stops. I know I need to use On Duplicate Key Update but I'm note sure how to properly add this.

My unique column 2.

cur.execute("""INSERT INTO logs (1,2,3) VALUES (%s,%s,%s) """,(line[0], line[1], line[2]))

If there is a duplicate to have it update that row/entry.

Tim Zimmermann

When I understand you correctly, what you are looking for is this:

cur.execute(""" INSERT INTO logs (1, 2, 3) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE 1=%s, 3=%s """, (line[0], line[1], line[2], line[0], line[2]))

Check also Insert on duplicate.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

UPDATE, INSERT and ON DUPLICATE KEY UPDATE in one query

分類Dev

Go:ON DUPLICATE KEY UPDATEでSQL RowsAffected

分類Dev

Java+MySQL - adding "on duplicate key update"

分類Dev

Mysql INSERT INTO ... SELECT .... ON DUPLICATE KEY UPDATE

分類Dev

python mysql DUPLICATE KEY UPDATE rrror

分類Dev

Mysql insert on duplicate key update and delete if key not exists

分類Dev

SQL Insert multiple record while using ON DUPLICATE KEY UPDATE

分類Dev

mysql insert on duplicate key update, check which one occurred

分類Dev

How to avoid duplicate key error in swift when iterating over a dictionary

分類Dev

how to combine duplicate key in dictionary and sum up values in swift?

分類Dev

How to update Elixir struct with key in variable

分類Dev

How to update table using foreign key in sql

分類Dev

独自の列を持つDUPLICATE KEY UPDATEオン

分類Dev

How to find duplicate and update column value of all but the most recent entry

分類Dev

How to do update if exist without creating a duplicate row in SQL?

分類Dev

How to update timestamp with mysql foreign key constraint on update cascade?

分類Dev

MySQL Update if duplicate row

分類Dev

ON DUPLICATE update nothing

分類Dev

HSQLDBの「ON DUPLICATE KEY UPDATE」機能はMYSQLのように動作しませんか?

分類Dev

複数行のMySQLON DUPLICATE KEY UPDATEを単一のクエリに挿入

分類Dev

VB.NETで「INSERT INTO table VALUES() ON DUPLICATE KEY UPDATE」を使用できません

分類Dev

INSERT INTO ... ON DUPLICATE KEY UPDATEは、PHPとmySQLで重複する値を更新しません

分類Dev

Can a foreign key be NULL and/or duplicate?

分類Dev

PostgreSQL BIGSERIAL and "duplicate key" on insert

分類Dev

How to stop the "insert or update on table ...violates foreign key constraint"?

分類Dev

How to update a map but only when key already exists

分類Dev

How to update key/value of a nested state object (React JS)

分類Dev

How to update table with sequentional on table without primary key?

分類Dev

How to update a key's value in an associative array in php

Related 関連記事

  1. 1

    UPDATE, INSERT and ON DUPLICATE KEY UPDATE in one query

  2. 2

    Go:ON DUPLICATE KEY UPDATEでSQL RowsAffected

  3. 3

    Java+MySQL - adding "on duplicate key update"

  4. 4

    Mysql INSERT INTO ... SELECT .... ON DUPLICATE KEY UPDATE

  5. 5

    python mysql DUPLICATE KEY UPDATE rrror

  6. 6

    Mysql insert on duplicate key update and delete if key not exists

  7. 7

    SQL Insert multiple record while using ON DUPLICATE KEY UPDATE

  8. 8

    mysql insert on duplicate key update, check which one occurred

  9. 9

    How to avoid duplicate key error in swift when iterating over a dictionary

  10. 10

    how to combine duplicate key in dictionary and sum up values in swift?

  11. 11

    How to update Elixir struct with key in variable

  12. 12

    How to update table using foreign key in sql

  13. 13

    独自の列を持つDUPLICATE KEY UPDATEオン

  14. 14

    How to find duplicate and update column value of all but the most recent entry

  15. 15

    How to do update if exist without creating a duplicate row in SQL?

  16. 16

    How to update timestamp with mysql foreign key constraint on update cascade?

  17. 17

    MySQL Update if duplicate row

  18. 18

    ON DUPLICATE update nothing

  19. 19

    HSQLDBの「ON DUPLICATE KEY UPDATE」機能はMYSQLのように動作しませんか?

  20. 20

    複数行のMySQLON DUPLICATE KEY UPDATEを単一のクエリに挿入

  21. 21

    VB.NETで「INSERT INTO table VALUES() ON DUPLICATE KEY UPDATE」を使用できません

  22. 22

    INSERT INTO ... ON DUPLICATE KEY UPDATEは、PHPとmySQLで重複する値を更新しません

  23. 23

    Can a foreign key be NULL and/or duplicate?

  24. 24

    PostgreSQL BIGSERIAL and "duplicate key" on insert

  25. 25

    How to stop the "insert or update on table ...violates foreign key constraint"?

  26. 26

    How to update a map but only when key already exists

  27. 27

    How to update key/value of a nested state object (React JS)

  28. 28

    How to update table with sequentional on table without primary key?

  29. 29

    How to update a key's value in an associative array in php

ホットタグ

アーカイブ