Home Explore Blog CI



postgresql

3rd chunk of `doc/src/sgml/ref/merge.sgml`
5a4233fc327360107eb584b4b0bcf05365b35bb60d04d6d10000000100000fa4
 update action, you must have the
   <literal>UPDATE</literal> privilege on the column(s)
   of the target table
   that are referred to in the <literal>SET</literal> clause.
   If you specify an insert action, you must have the <literal>INSERT</literal>
   privilege on the target table.
   If you specify a delete action, you must have the <literal>DELETE</literal>
   privilege on the target table.
   If you specify a <literal>DO NOTHING</literal> action, you must have
   the <literal>SELECT</literal> privilege on at least one column
   of the target table.
   You will also need <literal>SELECT</literal> privilege on any column(s)
   of the <replaceable class="parameter">data_source</replaceable> and
   of the target table referred to
   in any <literal>condition</literal> (including <literal>join_condition</literal>)
   or <literal>expression</literal>.
   Privileges are tested once at statement start and are checked
   whether or not particular <literal>WHEN</literal> clauses are executed.
  </para>

  <para>
   <command>MERGE</command> is not supported if the
   target table is a
   materialized view, foreign table, or if it has any
   rules defined on it.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>
   <varlistentry>
    <term><replaceable class="parameter">with_query</replaceable></term>
    <listitem>
     <para>
      The <literal>WITH</literal> clause allows you to specify one or more
      subqueries that can be referenced by name in the <command>MERGE</command>
      query. See <xref linkend="queries-with"/> and <xref linkend="sql-select"/>
      for details.  Note that <literal>WITH RECURSIVE</literal> is not supported
      by <command>MERGE</command>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">target_table_name</replaceable></term>
    <listitem>
     <para>
      The name (optionally schema-qualified) of the target table or view to
      merge into.  If <literal>ONLY</literal> is specified before a table
      name, matching rows are updated or deleted in the named table only.  If
      <literal>ONLY</literal> is not specified, matching rows are also updated
      or deleted in any tables inheriting from the named table.  Optionally,
      <literal>*</literal> can be specified after the table name to explicitly
      indicate that descendant tables are included.  The
      <literal>ONLY</literal> keyword and <literal>*</literal> option do not
      affect insert actions, which always insert into the named table only.
     </para>

     <para>
      If <replaceable class="parameter">target_table_name</replaceable> is a
      view, it must either be automatically updatable with no
      <literal>INSTEAD OF</literal> triggers, or it must have
      <literal>INSTEAD OF</literal> triggers for every type of action
      (<literal>INSERT</literal>, <literal>UPDATE</literal>, and
      <literal>DELETE</literal>) specified in the <literal>WHEN</literal>
      clauses.  Views with rules are not supported.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">target_alias</replaceable></term>
    <listitem>
     <para>
      A substitute name for the target table. When an alias is
      provided, it completely hides the actual name of the table.  For
      example, given <literal>MERGE INTO foo AS f</literal>, the remainder of the
      <command>MERGE</command> statement must refer to this table as
      <literal>f</literal> not <literal>foo</literal>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">source_table_name</replaceable></term>
    <listitem>
     <para>
      The name (optionally schema-qualified) of the source table, view, or
      transition table.  If <literal>ONLY</literal> is specified before the
      table name, matching rows are included from the named table only.  If
      <literal>ONLY</literal>

Title: MERGE Command Restrictions, Parameters and WITH Clause
Summary
This section details privilege requirements for the MERGE command's actions (UPDATE, INSERT, DELETE, DO NOTHING) on the target table. It also specifies that MERGE is unsupported for materialized views, foreign tables, or tables with rules. The section then defines parameters like 'with_query', which allows specifying subqueries (though WITH RECURSIVE is not supported), 'target_table_name', indicating the target table/view, and 'target_alias', a substitute name for the target table. Lastly it introduces 'source_table_name' the source table/view for the MERGE operation.