更新时间:2022-05-21 02:55:53
Postgres 9.5(自 2016-01-07 发布)提供了一个 "upsert" 命令,也称为 ON CONFLICT 子句插入:
Postgres 9.5 (released since 2016-01-07) offers an "upsert" command, also known as an ON CONFLICT clause to INSERT:
INSERT ... ON CONFLICT DO NOTHING/UPDATE
它解决了您在使用并发操作时可能遇到的许多微妙问题,其他一些答案提出了这些问题.
It solves many of the subtle problems you can run into when using concurrent operation, which some other answers propose.