Home Explore Blog CI



postgresql

3rd chunk of `doc/src/sgml/ref/delete.sgml`
bc726d29c03e8f77bca6dc090e22425bc49f1bfd269bd1370000000100000cd8
    <xref linkend="sql-declare"/>
      for more information about using cursors with
      <literal>WHERE CURRENT OF</literal>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">output_alias</replaceable></term>
    <listitem>
     <para>
      An optional substitute name for <literal>OLD</literal> or
      <literal>NEW</literal> rows in the <literal>RETURNING</literal> list.
     </para>

     <para>
      By default, old values from the target table can be returned by writing
      <literal>OLD.<replaceable class="parameter">column_name</replaceable></literal>
      or <literal>OLD.*</literal>, and new values can be returned by writing
      <literal>NEW.<replaceable class="parameter">column_name</replaceable></literal>
      or <literal>NEW.*</literal>.  When an alias is provided, these names are
      hidden and the old or new rows must be referred to using the alias.
      For example <literal>RETURNING WITH (OLD AS o, NEW AS n) o.*, n.*</literal>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">output_expression</replaceable></term>
    <listitem>
     <para>
      An expression to be computed and returned by the <command>DELETE</command>
      command after each row is deleted.  The expression can use any
      column names of the table named by <replaceable class="parameter">table_name</replaceable>
      or table(s) listed in <literal>USING</literal>.
      Write <literal>*</literal> to return all columns.
     </para>

     <para>
      A column name or <literal>*</literal> may be qualified using
      <literal>OLD</literal> or <literal>NEW</literal>, or the corresponding
      <replaceable class="parameter">output_alias</replaceable> for
      <literal>OLD</literal> or <literal>NEW</literal>, to cause old or new
      values to be returned.  An unqualified column name, or
      <literal>*</literal>, or a column name or <literal>*</literal> qualified
      using the target table name or alias will return old values.
     </para>

     <para>
      For a simple <command>DELETE</command>, all new values will be
      <literal>NULL</literal>.  However, if an <literal>ON DELETE</literal>
      rule causes an <command>INSERT</command> or <command>UPDATE</command>
      to be executed instead, the new values may be non-<literal>NULL</literal>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">output_name</replaceable></term>
    <listitem>
     <para>
      A name to use for a returned column.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1>
  <title>Outputs</title>

  <para>
   On successful completion, a <command>DELETE</command> command returns a command
   tag of the form
<screen>
DELETE <replaceable class="parameter">count</replaceable>
</screen>
   The <replaceable class="parameter">count</replaceable> is the number
   of rows deleted.  Note that the number may be less than the number of
   rows that matched the <replaceable
   class="parameter">condition</replaceable> when deletes were
   suppressed by a <literal>BEFORE DELETE</literal> trigger.  If <replaceable
   class="parameter">count</replaceable>

Title: DELETE Parameters: Output Alias and Expression, Outputs
Summary
This section describes the remaining DELETE parameters: output_alias (an optional alias for OLD or NEW rows in the RETURNING list), output_expression (an expression to be computed and returned after each row is deleted, allowing access to table columns), and output_name (a name for a returned column). Additionally, it outlines the output of a successful DELETE command, which returns a command tag indicating the number of rows deleted. This count may be lower than the number of matching rows if BEFORE DELETE triggers suppress deletions.