类似于在一个SQL语句中插入多个记录,可以原子地执行多个upsert吗?
例如

insert into students ("name","age") values ("sid",23) on conflict ("name") set "age"=12;
insert into students ("name","age") values ("jack",24) on conflict ("name") set "age"=14;
insert into students ("name","age") values ("tom",20) on conflict ("name") set "age"=13;

最佳答案

根据documentation的规定,以下操作应该有效:

INSERT INTO students ("name", "age") VALUES ("sid", 23), ("jack",24), ("tom",20)
ON CONFLICT ("name") DO UPDATE SET "age" = EXCLUDED.age;

关于sql - 在Postgres中是否可以有多个原子上的upsert操作?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48151963/

10-16 00:49