繁体   English   中英

Upsert 查询未更新 postgres 中的记录

[英]Upsert query is not updating the the records in postgres

我正在尝试从临时表 Upsert 到目标表,但我的 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声明为主键或至少具有唯一约束或索引。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM