| From: | Alexander Korotkov <aekorotkov(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: MERGE behavior with REPEATABLE READ isolation level |
| Date: | 2026-02-15 01:22:43 |
| Message-ID: | CAPpHfdsyCq2QKdzqKFZhWjsoiN-S8wsTMPCgZf3VW-yv+vpOkw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sun, Feb 15, 2026 at 3:20 AM Alexander Korotkov <aekorotkov(at)gmail(dot)com>
wrote:
> Hi hackers,
>
> I found it strange that ExecMergeMatched() checks for
> IsolationUsesXactSnapshot() in the TM_Deleted case, but not in the
> TM_Updated case. Indeed, EPQ works on the repeatable read isolation level!
>
> s1# create table test (id int primary key, val int);
> s1# insert into test values (1,0);
>
> s2# begin;
> s2# update test set val = val + 100;
>
> s1# MERGE INTO test t USING (VALUES (1, 100)) AS s (id, inc)
> ON t.id = s.id
> WHEN MATCHED THEN
> UPDATE SET val = t.val + s.inc
> WHEN NOT MATCHED THEN
> INSERT (id, val) VALUES (s.id, s.inc);
> (waiting ...)
>
> s2# commit;
> s1# MERGE 1
> s1# select * from test;
> id | val
> ----+-----
> 1 | 200
> (1 row)
>
Oh, sorry I missed the begin statement for s1. The complete case should
look like this.
s1# create table test (id int primary key, val int);
s1# insert into test values (1,0);
s2# begin;
s2# update test set val = val + 100;
s1# begin isolation level repeatable read;
s1# MERGE INTO test t USING (VALUES (1, 100)) AS s (id, inc)
ON t.id = s.id
WHEN MATCHED THEN
UPDATE SET val = t.val + s.inc
WHEN NOT MATCHED THEN
INSERT (id, val) VALUES (s.id, s.inc);
(waiting ...)
s2# commit;
s1# MERGE 1
s1# select * from test;
id | val
----+-----
1 | 200
(1 row)
------
Regards,
Alexander Korotkov
Supabase
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-02-15 01:33:42 | Re: CREATE ASSERTION: database level assertions feature |
| Previous Message | Alexander Korotkov | 2026-02-15 01:20:49 | MERGE behavior with REPEATABLE READ isolation level |