可能重复:
Insert, on duplicate update (postgresql)
Cannot SELECT from UPDATE RETURNING clause in postgresPostgreSQL的UPSERT查询
帮助理解我的语法错误。我尽量让这样的实施UPSERT查询的 PosgreSql:
create table tbl(key int, val int);
insert into tbl(key,val)
select distinct(key), 0 from unnest('{0,1,2,3,4,5}'::int[]) as key
where key not in (
update tbl set val = 1
where key = any('{0,1,2,3,4,5}'::int[])
returning key
);
错误是:
ERROR: syntax error at or near "tbl"
ROWS 6: update tbl set val = 1
^
********** Error **********
ERROR: syntax error at or near "tbl"
SQL state: 42601
Character: 167
但更新的子查询,而不嵌件工作做好。
任何最简单的方法来做upsert查询?
不,这不是重复 – potapuff