मुझे नहीं लगता कि PostgreSQL 9.3 में UPSERT स्टेटमेंट है, लेकिन आप यह कर सकते हैं:
with cte_dual as (
select
v_c1 as key,
v_c2 as pkey,
v_c3 as wcount,
v_c4 as dcount
), cte_update as (
update my_table as a set
wcount = b.wcount,
dcount = b.dcount
from cte_dual as b
where b.key = a.key and b.pkey = a.pkey
returning *
)
insert into my_table (key, pkey, wcount, dcount)
select d.key, d.pkey, d.wcount, d.dcount
from cte_dual as d
where not exists (select * from cte_update as u WHERE u.key = d.key and u.pkey = d.pkey)
आप कुछ इसी तरह के प्रश्न पढ़ सकते हैं:
- PostgreSQL में UPSERT (MERGE, INSERT ... ऑन डुप्लीकेट अपडेट) कैसे करें?
- PostgreSQL में डुप्लीकेट अपडेट पर डालें?