From 582f8b932cc515485bfdb84479f0600f91bbf9a7 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Wed, 18 May 2022 18:41:04 +0200 Subject: [PATCH v4] Link to MVCC docs in MERGE docs --- doc/src/sgml/mvcc.sgml | 15 ++++++++------- doc/src/sgml/ref/merge.sgml | 4 ++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/doc/src/sgml/mvcc.sgml b/doc/src/sgml/mvcc.sgml index 341fea524a..2f8d2b17ef 100644 --- a/doc/src/sgml/mvcc.sgml +++ b/doc/src/sgml/mvcc.sgml @@ -425,13 +425,13 @@ COMMIT; MERGE allows the user to specify various combinations of INSERT, UPDATE - or DELETE subcommands. A MERGE + and DELETE subcommands. A MERGE command with both INSERT and UPDATE subcommands looks similar to INSERT with an ON CONFLICT DO UPDATE clause but does not guarantee that either INSERT or UPDATE will occur. - If MERGE attempts an UPDATE or + If MERGE attempts an UPDATE or DELETE and the row is concurrently updated but the join condition still passes for the current target and the current source tuple, then MERGE will behave @@ -448,9 +448,9 @@ COMMIT; and execute the first one that succeeds. If MERGE attempts an INSERT and a unique index is present and a duplicate row is concurrently - inserted, then a uniqueness violation is raised. - MERGE does not attempt to avoid the - error by executing an UPDATE. + inserted, then a uniqueness violation error is raised; + MERGE does not attempt to avoid such + errors by evaluating MATCHED conditions. @@ -516,8 +516,9 @@ COMMIT; - UPDATE, DELETE, SELECT - FOR UPDATE, and SELECT FOR SHARE commands + UPDATE, DELETE, + MERGE, SELECT FOR UPDATE, + and SELECT FOR SHARE commands behave the same as SELECT in terms of searching for target rows: they will only find target rows that were committed as of the transaction start time. However, such a diff --git a/doc/src/sgml/ref/merge.sgml b/doc/src/sgml/ref/merge.sgml index f68aa09736..f0745d01c7 100644 --- a/doc/src/sgml/ref/merge.sgml +++ b/doc/src/sgml/ref/merge.sgml @@ -539,6 +539,10 @@ MERGE total_count + When MERGE is run concurrently with other commands + that modify the target table, the usual transaction isolation rules + apply; see for an explanation + on the behavior at each isolation level. You may also wish to consider using INSERT ... ON CONFLICT as an alternative statement which offers the ability to run an UPDATE if a concurrent INSERT -- 2.30.2