| From: | armand pirvu <armand(dot)pirvu(at)gmail(dot)com> |
|---|---|
| To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
| Subject: | upsert and update filtering |
| Date: | 2017-07-31 21:26:34 |
| Message-ID: | 83A34E99-40BD-4781-B2AA-AC085FE9F4B8@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Hi
create table dimc1
(
col1 integer not null,
col2 char(10),
primary key (col1)
);
create table dimc2
(
col1 integer not null,
col2 char(10),
primary key (col1)
);
testdb=# select * from dimc1 order by 1;
col1 | col2
------+------------
111 | foo111
112 | foo112
(2 rows)
testdb=# select * from dimc2 order by 1;
col1 | col2
------+------------
111 | foo111
112 | foo122
211 | foo211
In general it is my understanding it gows like this
insert into dimc1 select * from dimc2
on conflict (col1) do update
SET
col2 = EXCLUDED.col2
;
insert into dimc1 select * from dimc2
on conflict (col1) do update
SET
col2 = EXCLUDED.col2 returning *
;
So far so good
But what if in the conflict situation I want to performa the update ONLY if the record is different. The update seems to happen no matter what
In other words is there anyway I can filter the update to happen (based on the sample date) only for 112 since col2 is different ?
testdb=# select * from dimc1 order by 1;
col1 | col2
------+------------
112 | foo112
testdb=# select * from dimc2 order by 1;
col1 | col2
------+------------
112 | foo122
Thanks
Armand
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Geoghegan | 2017-07-31 21:31:30 | Re: upsert and update filtering |
| Previous Message | Seong Son (US) | 2017-07-31 21:15:18 | standby database crash |