, .
UPDATE.
( - ):
UPDATE accounts a
SET (status, field1, field2)
= (m.status, m.field1, m.field2)
FROM merge_accounts m
WHERE m.uid = a.uid
AND (a.status IS DISTINCT FROM m.status OR
a.field1 IS DISTINCT FROM m.field1 OR
a.field2 IS DISTINCT FROM m.field2)
RETURNING a.*;
- PostgreSQL MVCC . , . , - .
:
accounts merge_accounts , merge_accounts accounts, , :
UPDATE accounts a
SET (status, field1, field2)
= (m.status, m.field1, m.field2)
FROM merge_accounts m
WHERE a.uid = m.uid
AND m IS DISTINCT FROM a
RETURNING a.*;
NULL. .
, (quote):
merge_accounts , , non-pk
, , .. , , , .
UPDATE accounts a
SET (status, field1, field2)
= (COALESCE(m.status[1], a.status)
, COALESCE(m.field1[1], a.field1)
, COALESCE(m.field2[1], a.field2))
FROM merge_accounts m
WHERE m.uid = a.uid
AND (m.status[1] IS NOT NULL AND a.status IS DISTINCT FROM m.status[1]
OR m.field1[1] IS NOT NULL AND a.field1 IS DISTINCT FROM m.field1[1]
OR m.field2[1] IS NOT NULL AND a.field2 IS DISTINCT FROM m.field2[1])
RETURNING a.*
m.status IS NOT NULL , , , NULL merge_accounts.
m.status <> '{}', .
m.status[1] IS NOT NULL .
:
Jayadevan , :