]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/delete.sgml
Very minor formatting fixup in the refentry id field to remove
[postgresql] / doc / src / sgml / ref / delete.sgml
1 <REFENTRY ID="SQL-DELETE">
2  <REFMETA>
3   <REFENTRYTITLE>
4    DELETE
5   </REFENTRYTITLE>
6   <REFMISCINFO>SQL - Language Statements</REFMISCINFO>
7  </REFMETA>
8  <REFNAMEDIV>
9   <REFNAME>
10    DELETE
11   </REFNAME>
12   <REFPURPOSE>
13    Deletes rows from a table
14   </REFPURPOSE>
15   
16   
17  <REFSYNOPSISDIV>
18   <REFSYNOPSISDIVINFO>
19    <DATE>1998-04-15</DATE>
20   </REFSYNOPSISDIVINFO>
21   <SYNOPSIS>
22    DELETE FROM <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE> [ WHERE <REPLACEABLE CLASS="PARAMETER">condition</REPLACEABLE> ]
23   </SYNOPSIS>
24   
25   <REFSECT2 ID="R2-SQL-DELETE-1">
26    <REFSECT2INFO>
27     <DATE>1998-04-15</DATE>
28    </REFSECT2INFO>
29    <TITLE>
30     Inputs
31    </TITLE>
32    <PARA>
33    </PARA>
34    <VARIABLELIST>
35     <VARLISTENTRY>
36      <TERM>
37      </TERM>
38      <LISTITEM>
39       <PARA>
40        <VARIABLELIST>
41         <VARLISTENTRY>
42          <TERM>
43           <ReturnValue><replaceable class="parameter">table</replaceable></ReturnValue>
44          </TERM>
45          <LISTITEM>
46           <PARA>
47           The name of an existing table.
48           </PARA>
49          </LISTITEM>
50         </VARLISTENTRY>
51         <VARLISTENTRY>
52          <TERM>
53           <ReturnValue><replaceable class="parameter">condition</replaceable></ReturnValue>
54          </TERM>
55          <LISTITEM>
56           <PARA>
57            This is an SQL selection query which returns the rows which
58            are to be deleted.
59           </PARA>
60           <PARA>
61           Refer to the SELECT statement for further description
62           of the WHERE clause.
63           </PARA>
64          </LISTITEM>
65         </VARLISTENTRY>
66        </variablelist>
67      </LISTITEM>
68     </VARLISTENTRY>
69    </VARIABLELIST>
70   </REFSECT2>
71   
72   <REFSECT2 ID="R2-SQL-DELETE-2">
73    <REFSECT2INFO>
74     <DATE>1998-04-15</DATE>
75    </REFSECT2INFO>
76    <TITLE>
77     Outputs
78    </TITLE>
79    <PARA>
80    </PARA>
81    <VARIABLELIST>
82     <VARLISTENTRY>
83      <TERM>
84      </TERM>
85      <LISTITEM>
86       <PARA>
87        <VARIABLELIST>
88         <VARLISTENTRY>
89          <TERM>
90           <ReturnValue> DELETE <replaceable class="parameter">count</replaceable></ReturnValue>
91          </TERM>
92          <LISTITEM>
93           <PARA>
94            Message returned if items are successfully deleted. The
95            <replaceable class="parameter">count</replaceable> is the number
96            of rows deleted.
97           </PARA>
98           <PARA>
99            If <replaceable class="parameter">count</replaceable> is 0,
100            no rows are deleted.
101           </PARA>
102          </LISTITEM>
103         </VARLISTENTRY>
104        </variablelist>
105      </LISTITEM>
106     </VARLISTENTRY>
107    </VARIABLELIST>
108   </REFSECT2>
109 </REFSYNOPSISDIV>
110  
111  <REFSECT1 ID="R1-SQL-DELETE-1">
112   <REFSECT1INFO>
113    <DATE>1998-04-15</DATE>
114   </REFSECT1INFO>
115   <TITLE>
116    Description
117   </TITLE>
118   <PARA>
119    DELETE removes rows which satisfy the WHERE <replaceable class="parameter">condition</replaceable>,
120    from the specified table.
121   </PARA>
122   <PARA>
123    If the <replaceable class="parameter">condition</replaceable> is absent,
124    the effect is to delete all rows in the table.
125    The result is a valid, but empty table.
126   </PARA>
127   <PARA>
128    You must have write access to the table in order to modify
129    it, as well as read access to any table whose values are
130    read in the <replaceable class="parameter">condition</replaceable>.
131   </PARA>
132  </REFSECT1>
133   
134  <REFSECT1 ID="R1-SQL-DELETE-2">
135   <TITLE>
136    Usage
137   </TITLE>
138   <PARA>
139    Remove all films but musicals:
140   </PARA>
141   <ProgramListing>
142    DELETE FROM films WHERE kind &lt;&gt; 'Musical';
143
144    SELECT * FROM films;
145
146    code |title                    |did| date_prod|kind      |len
147    -----+-------------------------+---+----------+----------+------
148    UA501|West Side Story          |105|1961-01-03|Musical   | 02:32
149    TC901|The King and I           |109|1956-08-11|Musical   | 02:13
150    WD101|Bed Knobs and Broomsticks|111|          |Musical   | 01:57
151   </ProgramListing>
152   <para>
153    Clear the table films:
154   </para>
155   <programlisting>
156    DELETE FROM films;
157    
158    SELECT * FROM films;
159    code|title|did|date_prod|kind|len
160    ----+-----+---+---------+----+---
161    (0 rows)
162   </programlisting>      
163  </REFSECT1>
164  
165  <REFSECT1 ID="R1-SQL-DELETE-3">
166   <TITLE>
167    Compatibility
168   </TITLE>
169   <PARA>
170   </PARA>
171   
172   <REFSECT2 ID="R2-SQL-DELETE-4">
173    <REFSECT2INFO>
174     <DATE>1998-04-15</DATE>
175    </REFSECT2INFO>
176    <TITLE>
177     SQL92
178    </TITLE>
179    <PARA>
180    SQL92 defines a different syntax for a positioned DELETE statement:
181    </PARA>
182    
183    <synopsis>
184     DELETE FROM <replaceable class="parameter">table</replaceable> WHERE CURRENT OF <replaceable class="parameter">cursor</replaceable>
185    </synopsis>
186    <para>
187    where <replaceable class="parameter">cursor</replaceable> identifies an open cursor.</para>
188   </refsect2>
189  </refsect1>
190 </REFENTRY>
191
192 <!-- Keep this comment at the end of the file
193 Local variables:
194 mode: sgml
195 sgml-omittag:t
196 sgml-shorttag:t
197 sgml-minimize-attributes:nil
198 sgml-always-quote-attributes:t
199 sgml-indent-step:1
200 sgml-indent-data:t
201 sgml-parent-document:nil
202 sgml-default-dtd-file:"../reference.ced"
203 sgml-exposed-tags:nil
204 sgml-local-catalogs:"/usr/lib/sgml/catalog"
205 sgml-local-ecat-files:nil
206 End:
207 -->