Doc: Miscellaneous doc updates for MERGE.
authorDean Rasheed
Sun, 26 Feb 2023 09:04:04 +0000 (09:04 +0000)
committerDean Rasheed
Sun, 26 Feb 2023 09:04:04 +0000 (09:04 +0000)
Update a few places in the documentation that should mention MERGE
among the list of applicable commands. In a couple of places, a
slightly more detailed description of what happens for MERGE seems
appropriate.

Reviewed by Alvaro Herrera.

Discussion: http://postgr.es/m/CAEZATCWqHLcxab89ATMQZNGFG_mxDPM%2BjzkSbXKD3JYPfRGvtw%40mail.gmail.com

12 files changed:
doc/src/sgml/arch-dev.sgml
doc/src/sgml/ddl.sgml
doc/src/sgml/high-availability.sgml
doc/src/sgml/perform.sgml
doc/src/sgml/plpgsql.sgml
doc/src/sgml/protocol.sgml
doc/src/sgml/queries.sgml
doc/src/sgml/ref/create_publication.sgml
doc/src/sgml/ref/explain.sgml
doc/src/sgml/ref/prepare.sgml
doc/src/sgml/ref/set_transaction.sgml
doc/src/sgml/xfunc.sgml

index 1315ce962df5dff4eb323772d691174d27eeb5c4..8aeac029fcfc356e7a660582e75d63e06ac127b2 100644 (file)
    
 
    
-    The executor mechanism is used to evaluate all four basic SQL query
+    The executor mechanism is used to evaluate all five basic SQL query
     types: SELECTINSERT,
-    UPDATE, and DELETE.
+    UPDATEDELETE, and
+    MERGE.
     For SELECT, the top-level executor code
     only needs to send each row returned by the query plan tree
     off to the client.  INSERT ... SELECT,
-    UPDATE, and DELETE
+    UPDATEDELETE, and
+    MERGE
     are effectively SELECTs under a special
     top-level plan node called ModifyTable.
    
     mark the old row deleted.  For DELETE, the only
     column that is actually returned by the plan is the TID, and the
     ModifyTable node simply uses the TID to visit each
-    target row and mark it deleted.
+    target row and mark it deleted.  For MERGE, the
+    planner joins the source and target relations, and includes all
+    column values required by any of the WHEN clauses,
+    plus the TID of the target row; this data is fed up to the
+    ModifyTable node, which uses the information to
+    work out which WHEN clause to execute, and then
+    inserts, updates or deletes the target row, as required.
    
 
    
index 585cd130f041bf1e64e7f3c75bdf3caf9b889e12..6653829a2760cddf7aac437cd77cc9b4ad06a615 100644 (file)
@@ -1777,7 +1777,8 @@ REVOKE ALL ON accounts FROM PUBLIC;
        view, or other table-like object.
        Also allows use of COPY TO.
        This privilege is also needed to reference existing column values in
-       UPDATE or DELETE.
+       UPDATEDELETE,
+       or MERGE.
        For sequences, this privilege also allows use of the
        currval function.
        For large objects, this privilege allows the object to be read.
index b2b31293972d691c94e85cb0e63e21c9ef39fce3..e4f49031baf1251ce637456e37be2620ee2f4038 100644 (file)
@@ -1617,7 +1617,8 @@ synchronous_standby_names = 'ANY 2 (s1, s2, s3)'
      
       
        Data Manipulation Language (DML): INSERT,
-       UPDATEDELETECOPY FROM,
+       UPDATEDELETE,
+       MERGECOPY FROM,
        TRUNCATE.
        Note that there are no allowed actions that result in a trigger
        being executed during recovery.  This restriction applies even to
index c3ee47b3d6d34c71090e5309b188577ce7f37bf3..ad21cecde1746578300ae095830a3209fd9d26a5 100644 (file)
@@ -788,9 +788,10 @@ ROLLBACK;
 
    
     As seen in this example, when the query is an INSERT,
-    UPDATE, or DELETE command, the actual work of
+    UPDATEDELETE, or
+    MERGE command, the actual work of
     applying the table changes is done by a top-level Insert, Update,
-    or Delete plan node.  The plan nodes underneath this node perform
+    Delete, or Merge plan node.  The plan nodes underneath this node perform
     the work of locating the old rows and/or computing the new data.
     So above, we see the same sort of bitmap table scan we've seen already,
     and its output is fed to an Update node that stores the updated rows.
@@ -803,7 +804,8 @@ ROLLBACK;
    
 
    
-    When an UPDATE or DELETE command affects an
+    When an UPDATEDELETE, or
+    MERGE command affects an
     inheritance hierarchy, the output might look like this:
 
 
index cf387dfc3f1169cb62a50a910bb17e58acf988e9..21cc7c6d9d1944c35ca5d2f967ddb19d517d4d10 100644 (file)
@@ -1044,7 +1044,8 @@ INSERT INTO mytable VALUES (1,'one'), (2,'two');
      PL/pgSQL variable values can be
      automatically inserted into optimizable SQL commands, which
      are SELECTINSERT,
-     UPDATEDELETE, and certain
+     UPDATEDELETE,
+     MERGE, and certain
      utility commands that incorporate one of these, such
      as EXPLAIN and CREATE TABLE ... AS
      SELECT.  In these commands,
index 0770d278c39425e8fdd95ecbb8d590372dce89fa..405046f83cd038deea8aa50f924f6d53e6967e68 100644 (file)
@@ -4110,6 +4110,13 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
         rows is the number of rows updated.
        
 
+       
+        For a MERGE command, the tag is
+        MERGE rows where
+        rows is the number of rows inserted,
+        updated, or deleted.
+       
+
        
         For a SELECT or CREATE TABLE AS
         command, the tag is SELECT rows
index 95559ef1ac470eb9063392ca39874e5d56183bf4..61b1373fda2aca4c05de444eb2c118980d097ae4 100644 (file)
@@ -2058,8 +2058,8 @@ SELECT select_list FROM table_expression
    in a WITH clause can be a SELECT,
    INSERTUPDATE, or DELETE; and the
    WITH clause itself is attached to a primary statement that can
-   also be a SELECTINSERTUPDATE, or
-   DELETE.
+   be a SELECTINSERTUPDATE,
+   DELETE, or MERGE.
   
 
  
@@ -2581,7 +2581,8 @@ SELECT * FROM w AS w1 JOIN w AS w2 ON w1.f = w2.f;
   
    The examples above only show WITH being used with
    SELECT, but it can be attached in the same way to
-   INSERTUPDATE, or DELETE.
+   INSERTUPDATE,
+   DELETE, or MERGE.
    In each case it effectively provides temporary table(s) that can
    be referred to in the main command.
   
@@ -2591,8 +2592,9 @@ SELECT * FROM w AS w1 JOIN w AS w2 ON w1.f = w2.f;
    Data-Modifying Statements in <literal>WITH</literal>
 
    
-    You can use data-modifying statements (INSERT,
-    UPDATE, or DELETE) in WITH.  This
+    You can use most data-modifying statements (INSERT,
+    UPDATE, or DELETE, but not
+    MERGE) in WITH.  This
     allows you to perform several different operations in the same query.
     An example is:
 
index e229384e6ff35c01c2bb1cf69d310411a5ffd219..7ab7e77f33795bb4f23b7a8fcee59566fddb67c8 100644 (file)
@@ -299,6 +299,12 @@ CREATE PUBLICATION name
    UPDATE, or it may not be published at all.
   
 
+  
+   For a MERGE command, the publication will publish an
+   INSERTUPDATE, or DELETE
+   for each row inserted, updated, or deleted.
+  
+
   
    ATTACHing a table into a partition tree whose root is
    published using a publication with publish_via_partition_root
index d4895b9d7d4f4b8d19eeb373af870bc4afea3729..0fce6224232f6493461e2eb7d79973b6bb6b11fd 100644 (file)
@@ -94,7 +94,8 @@ EXPLAIN [ ANALYZE ] [ VERBOSE ] statement
     statement will happen as usual.  If you wish to use
     EXPLAIN ANALYZE on an
     INSERTUPDATE,
-    DELETECREATE TABLE AS,
+    DELETEMERGE,
+    CREATE TABLE AS,
     or EXECUTE statement
     without letting the command affect your data, use this approach:
 
@@ -272,7 +273,8 @@ ROLLBACK;
     
      
       Any SELECTINSERTUPDATE,
-      DELETEVALUESEXECUTE,
+      DELETEMERGE,
+      VALUESEXECUTE,
       DECLARECREATE TABLE AS, or
       CREATE MATERIALIZED VIEW AS statement, whose execution
       plan you wish to see.
index aae91946c75760cb04e3415f38979e8bec0894ef..d7b85394e8e9ce55aaa6db50519f930b676948fa 100644 (file)
@@ -116,7 +116,8 @@ PREPARE name [ ( 
     
      
       Any SELECTINSERTUPDATE,
-      DELETE, or VALUES statement.
+      DELETEMERGE, or VALUES
+      statement.
      
     
    
index d394e622f8af9a49e656ed633ccc341d24a44ac2..727a92757e80daffd143d257169eb99cc88cc60c 100644 (file)
@@ -121,7 +121,8 @@ SET SESSION CHARACTERISTICS AS TRANSACTION transa
    The transaction isolation level cannot be changed after the first query or
    data-modification statement (SELECT,
    INSERTDELETE,
-   UPDATEFETCH, or
+   UPDATEMERGE,
+   FETCH, or
    COPY) of a transaction has been executed.  See
     for more information about transaction
    isolation and concurrency control.
@@ -131,8 +132,9 @@ SET SESSION CHARACTERISTICS AS TRANSACTION transa
    The transaction access mode determines whether the transaction is
    read/write or read-only.  Read/write is the default.  When a
    transaction is read-only, the following SQL commands are
-   disallowed: INSERTUPDATE,
-   DELETE, and COPY FROM if the
+   disallowed: INSERTUPDATE,
+   DELETEMERGE, and
+   COPY FROM if the
    table they would write to is not a temporary table; all
    CREATEALTER, and
    DROP commands; COMMENT,
@@ -169,7 +171,8 @@ SET SESSION CHARACTERISTICS AS TRANSACTION transa
    start of a transaction, before the first query or
    data-modification statement (SELECT,
    INSERTDELETE,
-   UPDATEFETCH, or
+   UPDATEMERGE,
+   FETCH, or
    COPY) of the transaction.  Furthermore, the transaction
    must already be set to SERIALIZABLE or
    REPEATABLE READ isolation level (otherwise, the snapshot
index b8cefb9c2ca739bc28413baa76f7860cda12d822..701432fdf03e7ecb7d2c3faf8bdfc7299fdc8952 100644 (file)
      language can be packaged together and defined as a function.
      Besides SELECT queries, the commands can include data
      modification queries (INSERT,
-     UPDATE, and DELETE), as well as
+     UPDATEDELETE, and
+     MERGE), as well as
      other SQL commands. (You cannot use transaction control commands, e.g.,
      COMMITSAVEPOINT, and some utility
      commands, e.g.,  VACUUM, in SQL functions.)