11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/ref/delete.sgml,v 1.22 2005/01/09 05:57:45 tgl Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/ref/delete.sgml,v 1.23 2005/04/07 01:51:37 neilc Exp $
33PostgreSQL documentation
44-->
55
@@ -20,7 +20,9 @@ PostgreSQL documentation
2020
2121 <refsynopsisdiv>
2222<synopsis>
23- DELETE FROM [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
23+ DELETE FROM [ ONLY ] <replaceable class="PARAMETER">table</replaceable>
24+ [ USING <replaceable class="PARAMETER">usinglist</replaceable> ]
25+ [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
2426</synopsis>
2527 </refsynopsisdiv>
2628
@@ -49,10 +51,19 @@ DELETE FROM [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ WHERE
4951 <literal>ONLY</literal> clause.
5052 </para>
5153
54+ <para>
55+ There are two ways to delete rows in a table using information
56+ contained in other tables in the database: using sub-selects, or
57+ specifying additional tables in the <literal>USING</literal> clause.
58+ Which technique is more appropriate depends on the specific
59+ circumstances.
60+ </para>
61+
5262 <para>
5363 You must have the <literal>DELETE</literal> privilege on the table
5464 to delete from it, as well as the <literal>SELECT</literal>
55- privilege for any table whose values are read in the <replaceable
65+ privilege for any table in the <literal>USING</literal> clause or
66+ whose values are read in the <replaceable
5667 class="parameter">condition</replaceable>.
5768 </para>
5869 </refsect1>
@@ -70,6 +81,20 @@ DELETE FROM [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ WHERE
7081 </listitem>
7182 </varlistentry>
7283
84+ <varlistentry>
85+ <term><replaceable class="PARAMETER">usinglist</replaceable></term>
86+ <listitem>
87+ <para>
88+ A list of table expressions, allowing columns from other tables
89+ to appear in the <literal>WHERE</> condition. This is similar
90+ to the list of tables that can be specified in the <xref
91+ linkend="sql-from" endterm="sql-from-title"> of a
92+ <command>SELECT</command> statement; for example, an alias for
93+ the table name can be specified.
94+ </para>
95+ </listitem>
96+ </varlistentry>
97+
7398 <varlistentry>
7499 <term><replaceable class="parameter">condition</replaceable></term>
75100 <listitem>
@@ -105,10 +130,11 @@ DELETE <replaceable class="parameter">count</replaceable>
105130
106131 <para>
107132 <productname>PostgreSQL</productname> lets you reference columns of
108- other tables in the <literal>WHERE</> condition. For example, to
109- delete all films produced by a given producer, one might do
133+ other tables in the <literal>WHERE</> condition by specifying the
134+ other tables in the <literal>USING</literal> clause. For example,
135+ to delete all films produced by a given producer, one might do
110136<programlisting>
111- DELETE FROM films
137+ DELETE FROM films USING producers
112138 WHERE producer_id = producers.id AND producers.name = 'foo';
113139</programlisting>
114140 What is essentially happening here is a join between <structname>films</>
@@ -120,10 +146,13 @@ DELETE FROM films
120146 WHERE producer_id IN (SELECT id FROM producers WHERE name = 'foo');
121147</programlisting>
122148 In some cases the join style is easier to write or faster to
123- execute than the sub-select style. One objection to the join style
124- is that there is no explicit list of what tables are being used,
125- which makes the style somewhat error-prone; also it cannot handle
126- self-joins.
149+ execute than the sub-select style.
150+ </para>
151+
152+ <para>
153+ If <varname>add_missing_from</varname> is enabled, any relations
154+ mentioned in the <literal>WHERE</literal> condition will be
155+ implicitly added to the <literal>USING</literal> clause.
127156 </para>
128157 </refsect1>
129158
@@ -149,9 +178,10 @@ DELETE FROM films;
149178 <title>Compatibility</title>
150179
151180 <para>
152- This command conforms to the SQL standard, except that the ability to
153- reference other tables in the <literal>WHERE</> clause is a
154- <productname>PostgreSQL</productname> extension.
181+ This command conforms to the SQL standard, except that the
182+ <literal>USING</> clause and the ability to reference other tables
183+ in the <literal>WHERE</> clause are <productname>PostgreSQL</>
184+ extensions.
155185 </para>
156186 </refsect1>
157187</refentry>
0 commit comments