gpt4 book ai didi

sql - Postgres : on conflict with implicit conflict target

转载 作者:行者123 更新时间:2023-11-29 12:40:02 29 4
gpt4 key购买 nike

Postgres 10 和 11 的插入规范说:

ON CONFLICT [ conflict_target ] conflict_action

我有一张 table :

create table c (
e text not null,
m text not null,
v numeric not null,
PRIMARY KEY (e, m)
)

我想做

insert into candle values (...) 
on conflict do update set
v = 5

但是我得到一个错误:

ON CONFLICT DO UPDATE requires inference specification or constraint name Hint: For example, ON CONFLICT (column_name)

为什么我必须提供一个冲突的目标?如何提供主键或其他一些列集?

最佳答案

是的,<em>conflict_target</em>是可选的,但仅适用于 DO NOTHING .

根据 the documentation :

For ON CONFLICT DO NOTHING, it is optional to specify a <em>conflict_target</em>; when omitted, conflicts with all usable constraints (and unique indexes) are handled. For ON CONFLICT DO UPDATE, a <em>conflict_target</em> must be provided.

关于sql - Postgres : on conflict with implicit conflict target,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55342771/

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