Upsert 查询没有更新 postgres 中的记录

Upsert query is not updating the the records in postgres

我正在尝试从临时 table 更新插入目标 table 但是 我的 upsert 查询没有更新 postgresql 中的记录。虽然它是插入但不是更新。 请查找以下查询:

Insert into store 
Select t.* from store_temp 
where t.id not in (select a. Id 
from store a) on conflict(id) 
DO
Update
Set source = EXCLUDED.Source

非常感谢任何帮助。

您的语法看起来正确,但我认为您不需要 where 子句。相反:

Insert into store ( . . . )
    select . . .
    from store_temp t
    on conflict (id) do update
        set source = EXCLUDED.Source;

. . . 用于列列表。我建议在 insert 秒内明确说明。

那么你需要确保 id 被声明为主键或者至少有一个唯一的约束或索引。