mirror of
https://github.com/postgres/postgres.git
synced 2025-05-08 07:21:33 +03:00
Doc: Miscellaneous doc updates for MERGE.
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
This commit is contained in:
parent
a033f9165c
commit
a6864751cd
@ -530,13 +530,15 @@
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
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: <command>SELECT</command>, <command>INSERT</command>,
|
types: <command>SELECT</command>, <command>INSERT</command>,
|
||||||
<command>UPDATE</command>, and <command>DELETE</command>.
|
<command>UPDATE</command>, <command>DELETE</command>, and
|
||||||
|
<command>MERGE</command>.
|
||||||
For <command>SELECT</command>, the top-level executor code
|
For <command>SELECT</command>, the top-level executor code
|
||||||
only needs to send each row returned by the query plan tree
|
only needs to send each row returned by the query plan tree
|
||||||
off to the client. <command>INSERT ... SELECT</command>,
|
off to the client. <command>INSERT ... SELECT</command>,
|
||||||
<command>UPDATE</command>, and <command>DELETE</command>
|
<command>UPDATE</command>, <command>DELETE</command>, and
|
||||||
|
<command>MERGE</command>
|
||||||
are effectively <command>SELECT</command>s under a special
|
are effectively <command>SELECT</command>s under a special
|
||||||
top-level plan node called <literal>ModifyTable</literal>.
|
top-level plan node called <literal>ModifyTable</literal>.
|
||||||
</para>
|
</para>
|
||||||
@ -552,7 +554,13 @@
|
|||||||
mark the old row deleted. For <command>DELETE</command>, the only
|
mark the old row deleted. For <command>DELETE</command>, the only
|
||||||
column that is actually returned by the plan is the TID, and the
|
column that is actually returned by the plan is the TID, and the
|
||||||
<literal>ModifyTable</literal> node simply uses the TID to visit each
|
<literal>ModifyTable</literal> node simply uses the TID to visit each
|
||||||
target row and mark it deleted.
|
target row and mark it deleted. For <command>MERGE</command>, the
|
||||||
|
planner joins the source and target relations, and includes all
|
||||||
|
column values required by any of the <literal>WHEN</literal> clauses,
|
||||||
|
plus the TID of the target row; this data is fed up to the
|
||||||
|
<literal>ModifyTable</literal> node, which uses the information to
|
||||||
|
work out which <literal>WHEN</literal> clause to execute, and then
|
||||||
|
inserts, updates or deletes the target row, as required.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -1777,7 +1777,8 @@ REVOKE ALL ON accounts FROM PUBLIC;
|
|||||||
view, or other table-like object.
|
view, or other table-like object.
|
||||||
Also allows use of <command>COPY TO</command>.
|
Also allows use of <command>COPY TO</command>.
|
||||||
This privilege is also needed to reference existing column values in
|
This privilege is also needed to reference existing column values in
|
||||||
<command>UPDATE</command> or <command>DELETE</command>.
|
<command>UPDATE</command>, <command>DELETE</command>,
|
||||||
|
or <command>MERGE</command>.
|
||||||
For sequences, this privilege also allows use of the
|
For sequences, this privilege also allows use of the
|
||||||
<function>currval</function> function.
|
<function>currval</function> function.
|
||||||
For large objects, this privilege allows the object to be read.
|
For large objects, this privilege allows the object to be read.
|
||||||
|
@ -1617,7 +1617,8 @@ synchronous_standby_names = 'ANY 2 (s1, s2, s3)'
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Data Manipulation Language (DML): <command>INSERT</command>,
|
Data Manipulation Language (DML): <command>INSERT</command>,
|
||||||
<command>UPDATE</command>, <command>DELETE</command>, <command>COPY FROM</command>,
|
<command>UPDATE</command>, <command>DELETE</command>,
|
||||||
|
<command>MERGE</command>, <command>COPY FROM</command>,
|
||||||
<command>TRUNCATE</command>.
|
<command>TRUNCATE</command>.
|
||||||
Note that there are no allowed actions that result in a trigger
|
Note that there are no allowed actions that result in a trigger
|
||||||
being executed during recovery. This restriction applies even to
|
being executed during recovery. This restriction applies even to
|
||||||
|
@ -788,9 +788,10 @@ ROLLBACK;
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
As seen in this example, when the query is an <command>INSERT</command>,
|
As seen in this example, when the query is an <command>INSERT</command>,
|
||||||
<command>UPDATE</command>, or <command>DELETE</command> command, the actual work of
|
<command>UPDATE</command>, <command>DELETE</command>, or
|
||||||
|
<command>MERGE</command> command, the actual work of
|
||||||
applying the table changes is done by a top-level Insert, Update,
|
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.
|
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,
|
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.
|
and its output is fed to an Update node that stores the updated rows.
|
||||||
@ -803,7 +804,8 @@ ROLLBACK;
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
When an <command>UPDATE</command> or <command>DELETE</command> command affects an
|
When an <command>UPDATE</command>, <command>DELETE</command>, or
|
||||||
|
<command>MERGE</command> command affects an
|
||||||
inheritance hierarchy, the output might look like this:
|
inheritance hierarchy, the output might look like this:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
|
@ -1044,7 +1044,8 @@ INSERT INTO mytable VALUES (1,'one'), (2,'two');
|
|||||||
<application>PL/pgSQL</application> variable values can be
|
<application>PL/pgSQL</application> variable values can be
|
||||||
automatically inserted into optimizable SQL commands, which
|
automatically inserted into optimizable SQL commands, which
|
||||||
are <command>SELECT</command>, <command>INSERT</command>,
|
are <command>SELECT</command>, <command>INSERT</command>,
|
||||||
<command>UPDATE</command>, <command>DELETE</command>, and certain
|
<command>UPDATE</command>, <command>DELETE</command>,
|
||||||
|
<command>MERGE</command>, and certain
|
||||||
utility commands that incorporate one of these, such
|
utility commands that incorporate one of these, such
|
||||||
as <command>EXPLAIN</command> and <command>CREATE TABLE ... AS
|
as <command>EXPLAIN</command> and <command>CREATE TABLE ... AS
|
||||||
SELECT</command>. In these commands,
|
SELECT</command>. In these commands,
|
||||||
|
@ -4110,6 +4110,13 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
|
|||||||
<replaceable>rows</replaceable> is the number of rows updated.
|
<replaceable>rows</replaceable> is the number of rows updated.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
For a <command>MERGE</command> command, the tag is
|
||||||
|
<literal>MERGE <replaceable>rows</replaceable></literal> where
|
||||||
|
<replaceable>rows</replaceable> is the number of rows inserted,
|
||||||
|
updated, or deleted.
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
For a <command>SELECT</command> or <command>CREATE TABLE AS</command>
|
For a <command>SELECT</command> or <command>CREATE TABLE AS</command>
|
||||||
command, the tag is <literal>SELECT <replaceable>rows</replaceable></literal>
|
command, the tag is <literal>SELECT <replaceable>rows</replaceable></literal>
|
||||||
|
@ -2058,8 +2058,8 @@ SELECT <replaceable>select_list</replaceable> FROM <replaceable>table_expression
|
|||||||
in a <literal>WITH</literal> clause can be a <command>SELECT</command>,
|
in a <literal>WITH</literal> clause can be a <command>SELECT</command>,
|
||||||
<command>INSERT</command>, <command>UPDATE</command>, or <command>DELETE</command>; and the
|
<command>INSERT</command>, <command>UPDATE</command>, or <command>DELETE</command>; and the
|
||||||
<literal>WITH</literal> clause itself is attached to a primary statement that can
|
<literal>WITH</literal> clause itself is attached to a primary statement that can
|
||||||
also be a <command>SELECT</command>, <command>INSERT</command>, <command>UPDATE</command>, or
|
be a <command>SELECT</command>, <command>INSERT</command>, <command>UPDATE</command>,
|
||||||
<command>DELETE</command>.
|
<command>DELETE</command>, or <command>MERGE</command>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<sect2 id="queries-with-select">
|
<sect2 id="queries-with-select">
|
||||||
@ -2581,7 +2581,8 @@ SELECT * FROM w AS w1 JOIN w AS w2 ON w1.f = w2.f;
|
|||||||
<para>
|
<para>
|
||||||
The examples above only show <literal>WITH</literal> being used with
|
The examples above only show <literal>WITH</literal> being used with
|
||||||
<command>SELECT</command>, but it can be attached in the same way to
|
<command>SELECT</command>, but it can be attached in the same way to
|
||||||
<command>INSERT</command>, <command>UPDATE</command>, or <command>DELETE</command>.
|
<command>INSERT</command>, <command>UPDATE</command>,
|
||||||
|
<command>DELETE</command>, or <command>MERGE</command>.
|
||||||
In each case it effectively provides temporary table(s) that can
|
In each case it effectively provides temporary table(s) that can
|
||||||
be referred to in the main command.
|
be referred to in the main command.
|
||||||
</para>
|
</para>
|
||||||
@ -2591,8 +2592,9 @@ SELECT * FROM w AS w1 JOIN w AS w2 ON w1.f = w2.f;
|
|||||||
<title>Data-Modifying Statements in <literal>WITH</literal></title>
|
<title>Data-Modifying Statements in <literal>WITH</literal></title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
You can use data-modifying statements (<command>INSERT</command>,
|
You can use most data-modifying statements (<command>INSERT</command>,
|
||||||
<command>UPDATE</command>, or <command>DELETE</command>) in <literal>WITH</literal>. This
|
<command>UPDATE</command>, or <command>DELETE</command>, but not
|
||||||
|
<command>MERGE</command>) in <literal>WITH</literal>. This
|
||||||
allows you to perform several different operations in the same query.
|
allows you to perform several different operations in the same query.
|
||||||
An example is:
|
An example is:
|
||||||
|
|
||||||
|
@ -299,6 +299,12 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
|
|||||||
<command>UPDATE</command>, or it may not be published at all.
|
<command>UPDATE</command>, or it may not be published at all.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
For a <command>MERGE</command> command, the publication will publish an
|
||||||
|
<command>INSERT</command>, <command>UPDATE</command>, or <command>DELETE</command>
|
||||||
|
for each row inserted, updated, or deleted.
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<command>ATTACH</command>ing a table into a partition tree whose root is
|
<command>ATTACH</command>ing a table into a partition tree whose root is
|
||||||
published using a publication with <literal>publish_via_partition_root</literal>
|
published using a publication with <literal>publish_via_partition_root</literal>
|
||||||
|
@ -94,7 +94,8 @@ EXPLAIN [ ANALYZE ] [ VERBOSE ] <replaceable class="parameter">statement</replac
|
|||||||
statement will happen as usual. If you wish to use
|
statement will happen as usual. If you wish to use
|
||||||
<command>EXPLAIN ANALYZE</command> on an
|
<command>EXPLAIN ANALYZE</command> on an
|
||||||
<command>INSERT</command>, <command>UPDATE</command>,
|
<command>INSERT</command>, <command>UPDATE</command>,
|
||||||
<command>DELETE</command>, <command>CREATE TABLE AS</command>,
|
<command>DELETE</command>, <command>MERGE</command>,
|
||||||
|
<command>CREATE TABLE AS</command>,
|
||||||
or <command>EXECUTE</command> statement
|
or <command>EXECUTE</command> statement
|
||||||
without letting the command affect your data, use this approach:
|
without letting the command affect your data, use this approach:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
@ -272,7 +273,8 @@ ROLLBACK;
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Any <command>SELECT</command>, <command>INSERT</command>, <command>UPDATE</command>,
|
Any <command>SELECT</command>, <command>INSERT</command>, <command>UPDATE</command>,
|
||||||
<command>DELETE</command>, <command>VALUES</command>, <command>EXECUTE</command>,
|
<command>DELETE</command>, <command>MERGE</command>,
|
||||||
|
<command>VALUES</command>, <command>EXECUTE</command>,
|
||||||
<command>DECLARE</command>, <command>CREATE TABLE AS</command>, or
|
<command>DECLARE</command>, <command>CREATE TABLE AS</command>, or
|
||||||
<command>CREATE MATERIALIZED VIEW AS</command> statement, whose execution
|
<command>CREATE MATERIALIZED VIEW AS</command> statement, whose execution
|
||||||
plan you wish to see.
|
plan you wish to see.
|
||||||
|
@ -116,7 +116,8 @@ PREPARE <replaceable class="parameter">name</replaceable> [ ( <replaceable class
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Any <command>SELECT</command>, <command>INSERT</command>, <command>UPDATE</command>,
|
Any <command>SELECT</command>, <command>INSERT</command>, <command>UPDATE</command>,
|
||||||
<command>DELETE</command>, or <command>VALUES</command> statement.
|
<command>DELETE</command>, <command>MERGE</command>, or <command>VALUES</command>
|
||||||
|
statement.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -121,7 +121,8 @@ SET SESSION CHARACTERISTICS AS TRANSACTION <replaceable class="parameter">transa
|
|||||||
The transaction isolation level cannot be changed after the first query or
|
The transaction isolation level cannot be changed after the first query or
|
||||||
data-modification statement (<command>SELECT</command>,
|
data-modification statement (<command>SELECT</command>,
|
||||||
<command>INSERT</command>, <command>DELETE</command>,
|
<command>INSERT</command>, <command>DELETE</command>,
|
||||||
<command>UPDATE</command>, <command>FETCH</command>, or
|
<command>UPDATE</command>, <command>MERGE</command>,
|
||||||
|
<command>FETCH</command>, or
|
||||||
<command>COPY</command>) of a transaction has been executed. See
|
<command>COPY</command>) of a transaction has been executed. See
|
||||||
<xref linkend="mvcc"/> for more information about transaction
|
<xref linkend="mvcc"/> for more information about transaction
|
||||||
isolation and concurrency control.
|
isolation and concurrency control.
|
||||||
@ -131,8 +132,9 @@ SET SESSION CHARACTERISTICS AS TRANSACTION <replaceable class="parameter">transa
|
|||||||
The transaction access mode determines whether the transaction is
|
The transaction access mode determines whether the transaction is
|
||||||
read/write or read-only. Read/write is the default. When a
|
read/write or read-only. Read/write is the default. When a
|
||||||
transaction is read-only, the following SQL commands are
|
transaction is read-only, the following SQL commands are
|
||||||
disallowed: <literal>INSERT</literal>, <literal>UPDATE</literal>,
|
disallowed: <command>INSERT</command>, <command>UPDATE</command>,
|
||||||
<literal>DELETE</literal>, and <literal>COPY FROM</literal> if the
|
<command>DELETE</command>, <command>MERGE</command>, and
|
||||||
|
<command>COPY FROM</command> if the
|
||||||
table they would write to is not a temporary table; all
|
table they would write to is not a temporary table; all
|
||||||
<literal>CREATE</literal>, <literal>ALTER</literal>, and
|
<literal>CREATE</literal>, <literal>ALTER</literal>, and
|
||||||
<literal>DROP</literal> commands; <literal>COMMENT</literal>,
|
<literal>DROP</literal> commands; <literal>COMMENT</literal>,
|
||||||
@ -169,7 +171,8 @@ SET SESSION CHARACTERISTICS AS TRANSACTION <replaceable class="parameter">transa
|
|||||||
start of a transaction, before the first query or
|
start of a transaction, before the first query or
|
||||||
data-modification statement (<command>SELECT</command>,
|
data-modification statement (<command>SELECT</command>,
|
||||||
<command>INSERT</command>, <command>DELETE</command>,
|
<command>INSERT</command>, <command>DELETE</command>,
|
||||||
<command>UPDATE</command>, <command>FETCH</command>, or
|
<command>UPDATE</command>, <command>MERGE</command>,
|
||||||
|
<command>FETCH</command>, or
|
||||||
<command>COPY</command>) of the transaction. Furthermore, the transaction
|
<command>COPY</command>) of the transaction. Furthermore, the transaction
|
||||||
must already be set to <literal>SERIALIZABLE</literal> or
|
must already be set to <literal>SERIALIZABLE</literal> or
|
||||||
<literal>REPEATABLE READ</literal> isolation level (otherwise, the snapshot
|
<literal>REPEATABLE READ</literal> isolation level (otherwise, the snapshot
|
||||||
|
@ -186,7 +186,8 @@
|
|||||||
language can be packaged together and defined as a function.
|
language can be packaged together and defined as a function.
|
||||||
Besides <command>SELECT</command> queries, the commands can include data
|
Besides <command>SELECT</command> queries, the commands can include data
|
||||||
modification queries (<command>INSERT</command>,
|
modification queries (<command>INSERT</command>,
|
||||||
<command>UPDATE</command>, and <command>DELETE</command>), as well as
|
<command>UPDATE</command>, <command>DELETE</command>, and
|
||||||
|
<command>MERGE</command>), as well as
|
||||||
other SQL commands. (You cannot use transaction control commands, e.g.,
|
other SQL commands. (You cannot use transaction control commands, e.g.,
|
||||||
<command>COMMIT</command>, <command>SAVEPOINT</command>, and some utility
|
<command>COMMIT</command>, <command>SAVEPOINT</command>, and some utility
|
||||||
commands, e.g., <literal>VACUUM</literal>, in <acronym>SQL</acronym> functions.)
|
commands, e.g., <literal>VACUUM</literal>, in <acronym>SQL</acronym> functions.)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user