当执行更新插入并且在冲突约束中有超过两行具有相同键并且我们执行更新集时会发生什么?
What happens when doing an upsert and has more than two rows with the same key in the on conflict constraint and we perform an UPDATE SET?
想象一下这样的事情:
INSERT INTO table1
(data_1, data_2, data_3)
VALUES %s
ON CONFLICT (data_2) where active
DO UPDATE SET
data_1 = EXCLUDED.data_1,
data_2 = EXCLUDED.data_2,
data_3 = EXCLUDED.data_3,
当超过两行使用相同的 data_2
键发生冲突时会发生什么情况?
查询是否会更新具有冲突的 do update set
的两行或更多行,还是会抛出错误?
doc 说
INSERT with an ON CONFLICT DO UPDATE clause is a “deterministic”
statement. This means that the command will not be allowed to affect
any single existing row more than once; a cardinality violation error
will be raised when this situation arises. Rows proposed for insertion
should not duplicate each other in terms of attributes constrained by
an arbiter index or constraint.
所以如果你在超过两行的 data2
上有冲突,它会抛出一个错误
想象一下这样的事情:
INSERT INTO table1
(data_1, data_2, data_3)
VALUES %s
ON CONFLICT (data_2) where active
DO UPDATE SET
data_1 = EXCLUDED.data_1,
data_2 = EXCLUDED.data_2,
data_3 = EXCLUDED.data_3,
当超过两行使用相同的 data_2
键发生冲突时会发生什么情况?
查询是否会更新具有冲突的 do update set
的两行或更多行,还是会抛出错误?
doc 说
INSERT with an ON CONFLICT DO UPDATE clause is a “deterministic” statement. This means that the command will not be allowed to affect any single existing row more than once; a cardinality violation error will be raised when this situation arises. Rows proposed for insertion should not duplicate each other in terms of attributes constrained by an arbiter index or constraint.
所以如果你在超过两行的 data2
上有冲突,它会抛出一个错误