使用重复键更新在 MariaDB 中批量插入

Batch insert in MariaDB with on duplicate key update

我有以下 table 分类:

id - int(10) primary key
contact - int(10)
list - int(10)

在联系人和列表上具有唯一索引。当我运行批量查询100条记录时:

INSERT INTO cl(list, contact) VALUES (?, ?) ON DUPLICATE KEY UPDATE cl.id = cl.id

在高压下它会在大约 20% 的情况下失败并出现以下错误:

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ON DUPLICATE KEY UPDATE cl.id = cl.id' at line 1

80% 的查询 运行 没问题。当我使用相同参数重新运行 失败查询时,再次失败 20%。

为什么有些查询失败,第二次执行时没有报错?

将查询更改为

INSERT IGNORE INTO cl(list, contact) VALUES (?, ?)

问题已解决。虽然不清楚为什么 mysql 抛出 java.sql.SQLSyntaxErrorException 而不是更明确的东西。