3
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5
<link rel="stylesheet" href="stylesheet.css" type="text/css">
6
<link rev="made" href="pgsql-docs@postgresql.org">
7
<meta name="generator" content="DocBook XSL Stylesheets V1.64.1">
8
<link rel="home" href="index.html" title="PostgreSQL 8.0.0beta5 Documentation">
9
<link rel="up" href="sql-commands.html" title="SQL Commands">
10
<link rel="previous" href="sql-declare.html" title="DECLARE">
11
<link rel="next" href="sql-dropaggregate.html" title="DROP AGGREGATE">
13
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
14
<a name="sql-delete"></a><div class="titlepage">
18
<div class="refnamediv">
20
<p>DELETE — delete rows of a table</p>
22
<a name="id2682894"></a><div class="refsynopsisdiv">
24
<pre class="synopsis">DELETE FROM [ ONLY ] <i class="replaceable"><tt>table</tt></i> [ WHERE <i class="replaceable"><tt>condition</tt></i> ]</pre>
26
<div class="refsect1" lang="en">
27
<a name="id2682922"></a><h2>Description</h2>
28
<p> <tt class="command">DELETE</tt> deletes rows that satisfy the
29
<tt class="literal">WHERE</tt> clause from the specified table. If the
30
<tt class="literal">WHERE</tt> clause is absent, the effect is to delete
31
all rows in the table. The result is a valid, but empty table.
33
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
34
<h3 class="title">Tip</h3>
35
<p> <a href="sql-truncate.html">TRUNCATE</a> is a
36
<span class="productname">PostgreSQL</span> extension which provides a
37
faster mechanism to remove all rows from a table.
40
<p> By default, <tt class="command">DELETE</tt> will delete rows in the
41
specified table and all its subtables. If you wish to only delete
42
from the specific table mentioned, you must use the
43
<tt class="literal">ONLY</tt> clause.
45
<p> You must have the <tt class="literal">DELETE</tt> privilege on the table
46
to delete from it, as well as the <tt class="literal">SELECT</tt>
47
privilege for any table whose values are read in the <i class="replaceable"><tt>condition</tt></i>.
50
<div class="refsect1" lang="en">
51
<a name="id2683009"></a><h2>Parameters</h2>
52
<div class="variablelist"><dl>
53
<dt><span class="term"><i class="replaceable"><tt>table</tt></i></span></dt>
54
<dd><p> The name (optionally schema-qualified) of an existing table.
56
<dt><span class="term"><i class="replaceable"><tt>condition</tt></i></span></dt>
57
<dd><p> A value expression that returns a value of type
58
<tt class="type">boolean</tt> that determines the rows which are to be
63
<div class="refsect1" lang="en">
64
<a name="id2683041"></a><h2>Outputs</h2>
65
<p> On successful completion, a <tt class="command">DELETE</tt> command returns a command
68
<pre class="screen">DELETE <i class="replaceable"><tt>count</tt></i></pre>
70
The <i class="replaceable"><tt>count</tt></i> is the number
71
of rows deleted. If <i class="replaceable"><tt>count</tt></i> is
72
0, no rows matched the <i class="replaceable"><tt>condition</tt></i> (this is not considered
76
<div class="refsect1" lang="en">
77
<a name="id2683084"></a><h2>Examples</h2>
78
<p> Delete all films but musicals:
80
<pre class="programlisting">DELETE FROM films WHERE kind <> 'Musical';</pre>
83
<p> Clear the table <tt class="literal">films</tt>:
85
<pre class="programlisting">DELETE FROM films;</pre>
89
<div class="refsect1" lang="en">
90
<a name="id2683112"></a><h2>Compatibility</h2>
91
<p> This command conforms to the SQL standard.