Home Explore Blog CI



postgresql

4th chunk of `doc/src/sgml/ref/merge.sgml`
16bc34e5e06dd820c704584e70d43638e535e237e9d684250000000100000fa1
 <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> is not specified, matching rows are also included
      from 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.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">source_query</replaceable></term>
    <listitem>
     <para>
      A query (<command>SELECT</command> statement or <command>VALUES</command>
      statement) that supplies the rows to be merged into the
      target table.
      Refer to the <xref linkend="sql-select"/>
      statement or <xref linkend="sql-values"/>
      statement for a description of the syntax.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">source_alias</replaceable></term>
    <listitem>
     <para>
      A substitute name for the data source. When an alias is
      provided, it completely hides the actual name of the table or the fact
      that a query was issued.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">join_condition</replaceable></term>
    <listitem>
     <para>
      <replaceable class="parameter">join_condition</replaceable> is
      an expression resulting in a value of type
      <type>boolean</type> (similar to a <literal>WHERE</literal>
      clause) that specifies which rows in the
      <replaceable class="parameter">data_source</replaceable>
      match rows in the target table.
     </para>
     <warning>
      <para>
       Only columns from the target table
       that attempt to match <replaceable class="parameter">data_source</replaceable>
       rows should appear in <replaceable class="parameter">join_condition</replaceable>.
       <replaceable class="parameter">join_condition</replaceable> subexpressions that
       only reference the target table's
       columns can affect which action is taken, often in surprising ways.
      </para>
      <para>
       If both <literal>WHEN NOT MATCHED BY SOURCE</literal> and
       <literal>WHEN NOT MATCHED [BY TARGET]</literal> clauses are specified,
       the <command>MERGE</command> command will perform a <literal>FULL</literal>
       join between <replaceable class="parameter">data_source</replaceable>
       and the target table.  For this to work, at least one
       <replaceable class="parameter">join_condition</replaceable> subexpression
       must use an operator that can support a hash join, or all of the
       subexpressions must use operators that can support a merge join.
      </para>
     </warning>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">when_clause</replaceable></term>
    <listitem>
     <para>
      At least one <literal>WHEN</literal> clause is required.
     </para>
     <para>
      The <literal>WHEN</literal> clause may specify <literal>WHEN

Title: MERGE Command Parameters: Source, Join Condition and WHEN Clause
Summary
This section details parameters for the MERGE command, including 'source_table_name' to specify the source table/view, 'source_query' for a query supplying rows to merge, and 'source_alias' as a substitute name. It also covers 'join_condition', a boolean expression defining row matching, and warns about target table column references. Finally it describes the requirement of at least one 'WHEN' clause.