1
1
<!--
2
- $PostgreSQL: pgsql/doc/src/sgml/ref/truncate.sgml,v 1.25 2008/03/28 00:21:55 tgl Exp $
2
+ $PostgreSQL: pgsql/doc/src/sgml/ref/truncate.sgml,v 1.26 2008/05/16 23:36:04 tgl Exp $
3
3
PostgreSQL documentation
4
4
-->
5
5
@@ -20,7 +20,8 @@ PostgreSQL documentation
20
20
21
21
<refsynopsisdiv>
22
22
<synopsis>
23
- TRUNCATE [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ CASCADE | RESTRICT ]
23
+ TRUNCATE [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ... ]
24
+ [ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]
24
25
</synopsis>
25
26
</refsynopsisdiv>
26
27
@@ -50,6 +51,25 @@ TRUNCATE [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ C
50
51
</listitem>
51
52
</varlistentry>
52
53
54
+ <varlistentry>
55
+ <term><literal>RESTART IDENTITY</literal></term>
56
+ <listitem>
57
+ <para>
58
+ Automatically restart sequences owned by columns of
59
+ the truncated table(s).
60
+ </para>
61
+ </listitem>
62
+ </varlistentry>
63
+
64
+ <varlistentry>
65
+ <term><literal>CONTINUE IDENTITY</literal></term>
66
+ <listitem>
67
+ <para>
68
+ Do not change the values of sequences. This is the default.
69
+ </para>
70
+ </listitem>
71
+ </varlistentry>
72
+
53
73
<varlistentry>
54
74
<term><literal>CASCADE</literal></term>
55
75
<listitem>
@@ -66,7 +86,7 @@ TRUNCATE [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ C
66
86
<listitem>
67
87
<para>
68
88
Refuse to truncate if any of the tables have foreign-key references
69
- from tables that are not to be truncated . This is the default.
89
+ from tables that are not listed in the command . This is the default.
70
90
</para>
71
91
</listitem>
72
92
</varlistentry>
@@ -119,11 +139,23 @@ TRUNCATE [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ C
119
139
cause visible inconsistency between the contents of the truncated
120
140
table and other tables in the database.
121
141
</para>
142
+ </warning>
143
+
144
+ <para>
145
+ <command>TRUNCATE</> is transaction-safe with respect to the data
146
+ in the tables: the truncation will be safely rolled back if the surrounding
147
+ transaction does not commit.
148
+ </para>
122
149
150
+ <warning>
123
151
<para>
124
- <command>TRUNCATE</> is transaction-safe, however: the truncation
125
- will be safely rolled back if the surrounding transaction does not
126
- commit.
152
+ Any <command>ALTER SEQUENCE RESTART</> operations performed as a
153
+ consequence of using the <literal>RESTART IDENTITY</> option are
154
+ nontransactional and will not be rolled back. To minimize risk,
155
+ these operations are performed only after all the rest of
156
+ <command>TRUNCATE</>'s work is done. In practice this will only
157
+ be an issue if <command>TRUNCATE</> is performed inside a
158
+ transaction block that is aborted afterwards.
127
159
</para>
128
160
</warning>
129
161
</refsect1>
@@ -132,13 +164,22 @@ TRUNCATE [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ C
132
164
<title>Examples</title>
133
165
134
166
<para>
135
- Truncate the tables <literal>bigtable</literal> and <literal>fattable</literal>:
167
+ Truncate the tables <literal>bigtable</literal> and
168
+ <literal>fattable</literal>:
136
169
137
170
<programlisting>
138
171
TRUNCATE bigtable, fattable;
139
172
</programlisting>
140
173
</para>
141
174
175
+ <para>
176
+ The same, and also reset any associated sequence generators:
177
+
178
+ <programlisting>
179
+ TRUNCATE bigtable, fattable RESTART IDENTITY;
180
+ </programlisting>
181
+ </para>
182
+
142
183
<para>
143
184
Truncate the table <literal>othertable</literal>, and cascade to any tables
144
185
that reference <literal>othertable</literal> via foreign-key
@@ -154,7 +195,10 @@ TRUNCATE othertable CASCADE;
154
195
<title>Compatibility</title>
155
196
156
197
<para>
157
- There is no <command>TRUNCATE</command> command in the SQL standard.
198
+ The draft SQL:2008 standard includes a <command>TRUNCATE</command> command,
199
+ but at this writing it is uncertain whether that will reach standardization
200
+ or be fully compatible with <productname>PostgreSQL</productname>'s
201
+ implementation.
158
202
</para>
159
203
</refsect1>
160
204
</refentry>
0 commit comments