我尝试使用postgres 12.8对分区表执行Upsert。查询使用CTE执行插入操作,然后执行更新,但我收到以下错误:
[23505] ERROR: duplicate key value violates
unique constraint "books_20221201_pkey" Detail:
Key (book_id, book_name)=(1,"abcd") already exists.
Where: SQL statement "INSERT INTO public.books_20221201 VALUES (NEW.*)"
下面是查询:
WITH bk_temp(book_id, book_name) AS (
SELECT * FROM ( VALUES
(1,
"abcd"
)
) AS a(book_id, book_name))
INSERT INTO books
(book_id,
book_name)
(Select t.book_id, t.book_name
FROM bk_temp t
ON CONFLICT(book_id, book_name)
DO Update
SET book_name="defg");
1条答案
按热度按时间bkhjykvo1#
The documentation无疑会:
带有
ON CONFLICT
子句得INSERT
语句不太可能按预期工作,因为ON CONFLICT
操作仅在指定得目的关系(而不是其子关系)上发生唯一违规得情况下执行.分区表本身不包含任何数据...