11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.31 2005/11/01 21:09:50 tgl Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.32 2006/02/19 00:04:26 neilc Exp $
33PostgreSQL documentation
44-->
55
@@ -21,7 +21,10 @@ PostgreSQL documentation
2121 <refsynopsisdiv>
2222<synopsis>
2323CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name</replaceable>
24- [ (<replaceable>column_name</replaceable> [, ...] ) ] [ [ WITH | WITHOUT ] OIDS ]
24+ [ (<replaceable>column_name</replaceable> [, ...] ) ]
25+ [ WITH OIDS | WITHOUT OIDS ]
26+ [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
27+ [ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]
2528 AS <replaceable>query</replaceable>
2629</synopsis>
2730 </refsynopsisdiv>
@@ -113,6 +116,65 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
113116 </listitem>
114117 </varlistentry>
115118
119+ <varlistentry>
120+ <term><literal>ON COMMIT</literal></term>
121+ <listitem>
122+ <para>
123+ The behavior of temporary tables at the end of a transaction
124+ block can be controlled using <literal>ON COMMIT</literal>.
125+ The three options are:
126+
127+ <variablelist>
128+ <varlistentry>
129+ <term><literal>PRESERVE ROWS</literal></term>
130+ <listitem>
131+ <para>
132+ No special action is taken at the ends of transactions.
133+ This is the default behavior.
134+ </para>
135+ </listitem>
136+ </varlistentry>
137+
138+ <varlistentry>
139+ <term><literal>DELETE ROWS</literal></term>
140+ <listitem>
141+ <para>
142+ All rows in the temporary table will be deleted at the end
143+ of each transaction block. Essentially, an automatic <xref
144+ linkend="sql-truncate" endterm="sql-truncate-title"> is done
145+ at each commit.
146+ </para>
147+ </listitem>
148+ </varlistentry>
149+
150+ <varlistentry>
151+ <term><literal>DROP</literal></term>
152+ <listitem>
153+ <para>
154+ The temporary table will be dropped at the end of the current
155+ transaction block.
156+ </para>
157+ </listitem>
158+ </varlistentry>
159+ </variablelist>
160+ </para>
161+ </listitem>
162+ </varlistentry>
163+
164+ <varlistentry>
165+ <term><literal>TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable></literal></term>
166+ <listitem>
167+ <para>
168+ The <replaceable class="PARAMETER">tablespace</replaceable> is the name
169+ of the tablespace in which the new table is to be created.
170+ If not specified,
171+ <xref linkend="guc-default-tablespace"> is used, or the database's
172+ default tablespace if <varname>default_tablespace</> is an empty
173+ string.
174+ </para>
175+ </listitem>
176+ </varlistentry>
177+
116178 <varlistentry>
117179 <term><replaceable>query</replaceable></term>
118180 <listitem>
@@ -168,6 +230,20 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
168230<programlisting>
169231CREATE TABLE films_recent AS
170232 SELECT * FROM films WHERE date_prod >= '2002-01-01';
233+ </programlisting>
234+ </para>
235+
236+ <para>
237+ Create a new temporary table that will be dropped at commit
238+ <literal>films_recent</literal> with oids consisting of only
239+ recent entries from the table <literal>films</literal> using a
240+ prepared statement:
241+
242+ <programlisting>
243+ PREPARE recentfilms(date) AS
244+ SELECT * FROM films WHERE date_prod > $1;
245+ CREATE TEMP TABLE films_recent WITH OIDS ON COMMIT DROP AS
246+ EXECUTE recentfilms('2002-01-01');
171247</programlisting>
172248 </para>
173249 </refsect1>
@@ -188,13 +264,6 @@ CREATE TABLE films_recent AS
188264 </para>
189265 </listitem>
190266
191- <listitem>
192- <para>
193- The standard defines an <literal>ON COMMIT</literal> clause;
194- this is not currently implemented by <productname>PostgreSQL</>.
195- </para>
196- </listitem>
197-
198267 <listitem>
199268 <para>
200269 The standard defines a <literal>WITH [ NO ] DATA</literal> clause;
@@ -219,6 +288,14 @@ CREATE TABLE films_recent AS
219288 for details.
220289 </para>
221290 </listitem>
291+
292+ <listitem>
293+ <para>
294+ The <productname>PostgreSQL</productname> concept of tablespaces is not
295+ part of the standard. Hence, the clause <literal>TABLESPACE</literal>
296+ is an extension.
297+ </para>
298+ </listitem>
222299 </itemizedlist>
223300 </para>
224301 </refsect1>