SQL Error [42601]: ERROR: syntax error at or near "select" in Dbeaver PostgreSQL editor

Viewed 2581
insert into dwb_weekly_snapshot_03032021 (jp_number, ct_id)
select imjp_number, imct_id
from dummy_data_03032021
on conflict (jp_number) do update 
  set ct_id = select imct_id from dummy_data_03032021 where imjp_number=jp_number;

SQL Error [42601]: ERROR: syntax error at or near "select" Position: 166

I am updating ct_id value into table dwb_weekly_snapshot_03032021 from dummy_data_03032021 if jpnumber=imjp_number otherwise I have to insert both jp_number and ct_id value into table dwb_weekly_snapshot_03032021 from dummy_data_03032021 keeping other column value intact

Either I tried this also

UPDATE dwb_weekly_snapshot_03032021 SET dwb_weekly_snapshot_03032021.jp_number=dummy_data_03032021.imjp_number, dwb_weekly_snapshot_03032021.ct_id= dummy_data_03032021.imct_id WHERE dwb_weekly_snapshot_03032021.jp_number=dummy_data_03032021.imjp_number;
INSERT INTO dwb_weekly_snapshot_03032021 (jp_number, ct_id) SELECT imjp_number,imct_id from dummy_data_03032021 WHERE NOT EXISTS (SELECT 1 FROM dummy_data_03032021 WHERE dwb_weekly_snapshot_03032021.jp_number=dummy_data_03032021.imjp_number);

Got error:SQL Error [42P01]: ERROR: missing FROM-clause entry for table "dummy_data_03032021" Position: 222

USING EXCLUDED got beloew error SQL Error [42P10]: ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification

insert into dwb_weekly_snapshot_03032021 (jp_number, ct_id)
select imjp_number, imct_id
from dummy_data_03032021
on conflict (jp_number) do update set ct_id = EXCLUDED.ct_id 
0 Answers
Related