gpt4 book ai didi

sql - Postgresql 更新插入查询

转载 作者:行者123 更新时间:2023-11-29 13:06:56 27 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Insert, on duplicate update (postgresql)
Cannot SELECT from UPDATE RETURNING clause in postgres

帮助理解我的语法错误。我尝试在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 查询方法?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com