简体   繁体   中英

Upsert query is not updating the the records in postgres

I am trying to Upsert into the target table from temp table but My upsert query is not updating the records in postgresql. Although it is inserting but not updating. Please find below query:

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

Any helping hand would be really appreciated.

Your syntax looks correct, but I don't think you want the where clause. Instead:

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

The . . . . . . are for the column list. I recommend being explicit in insert s.

Then you need to be sure that id is declared as the primary key or at least has a unique constraint or index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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