非互換
Fujitsu Enterprise Postgres 16 SP1では、MERGEの対象テーブルの行が、すでに更新や削除済みであった場合にエラーとなるように変更します。
session 1
postgres=# BEGIN; BEGIN postgres=*# MERGE INTO pa_target t postgres-*# USING (SELECT 1 as key, 'pa_merge1' as val) s postgres-*# ON s.key = t.key postgres-*# WHEN NOT MATCHED THEN postgres-*# INSERT VALUES (s.key, s.val) postgres-*# WHEN MATCHED THEN postgres-*# UPDATE set val = t.val || ' updated by ' || s.val; MERGE 1
session 2
postgres=# BEGIN; BEGIN postgres=*# MERGE INTO pa_target t postgres-*# USING (VALUES (1), (1)) v(a) postgres-*# ON t.key = v.a postgres-*# WHEN MATCHED THEN postgres-*# UPDATE set val = t.val || ' updated by pa_merge2c_dup'; (session 1のロックによる待ち)
session 1
postgres=*# COMMIT; COMMIT
session 2
MERGE 1 (MERGEが正常終了)
session 1
postgres=# BEGIN; BEGIN postgres=*# MERGE INTO pa_target t postgres-*# USING (SELECT 1 as key, 'pa_merge1' as val) s postgres-*# ON s.key = t.key postgres-*# WHEN NOT MATCHED THEN postgres-*# INSERT VALUES (s.key, s.val) postgres-*# WHEN MATCHED THEN postgres-*# UPDATE set val = t.val || ' updated by ' || s.val; MERGE 1
session 2
postgres=# BEGIN; BEGIN postgres=*# MERGE INTO pa_target t postgres-*# USING (VALUES (1), (1)) v(a) postgres-*# ON t.key = v.a postgres-*# WHEN MATCHED THEN postgres-*# UPDATE set val = t.val || ' updated by pa_merge2c_dup'; (session 1のロックによる待ち)
session 1
postgres=*# COMMIT; COMMIT
session 2
ERROR: MERGE command cannot affect row a second time
対処方法
ありません。