更新时间:2023-02-14 19:00:34
查询 3 是 Postgres 9.5 中引入的UPSERT"(= UPDATE 或 INSERT)的 Postgres 语法.
Query 3 is the Postgres syntax for "UPSERT" (= UPDATE or INSERT), introduced in Postgres 9.5.
来自文档:
ON CONFLICT DO UPDATE
保证原子的 INSERT
或 UPDATE
结果;如果没有独立误差,这两个结果之一是保证,即使在高并发下.这也称为 UPSERT
–“UPDATE
或 INSERT
”.
ON CONFLICT DO UPDATE
guarantees an atomicINSERT
orUPDATE
outcome; provided there is no independent error, one of those two outcomes is guaranteed, even under high concurrency. This is also known asUPSERT
– “UPDATE
orINSERT
”.
这是您要达到的目标的***实践.
This is the best practice for what you are trying to achieve.