11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.9 2001/01/13 23:58:55 petere Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.10 2001/03/20 20:54:41 tgl Exp $
33Postgres documentation
44-->
55
@@ -15,7 +15,7 @@ Postgres documentation
1515 SELECT INTO
1616 </refname>
1717 <refpurpose>
18- Create a new table from an existing table or view
18+ Creates a new table from the results of a SELECT
1919 </refpurpose></refnamediv>
2020 <refsynopsisdiv>
2121 <refsynopsisdivinfo>
@@ -48,51 +48,112 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
4848
4949 <refsect2 id="R2-SQL-SELECTINTO-1">
5050 <refsect2info>
51- <date>1998-09-22 </date>
51+ <date>2001-03-20 </date>
5252 </refsect2info>
5353 <title>
5454 Inputs
5555 </title>
56+
57+ <para>
58+ <variablelist>
59+ <varlistentry>
60+ <term>TEMPORARY</term>
61+ <term>TEMP</term>
62+ <listitem>
63+ <para>
64+ If TEMPORARY or TEMP is specified,
65+ the output table is created only within this session, and is
66+ automatically dropped on session exit.
67+ Existing permanent tables with the same name are not visible
68+ (in this session) while the temporary table exists.
69+ Any indexes created on a temporary table are automatically
70+ temporary as well.
71+ </para>
72+ </listitem>
73+ </varlistentry>
74+
75+ <varlistentry>
76+ <term><replaceable class="PARAMETER">new_table</replaceable></term>
77+ <listitem>
78+ <para>
79+ The name of the new table to be created.
80+ This table must not already exist. However, a temporary table
81+ can be created that has the same name as an existing permanent
82+ table.
83+ </para>
84+ </listitem>
85+ </varlistentry>
86+ </variablelist>
87+ </para>
88+
5689 <para>
57- All input fields are described in detail for
90+ All other inputs are described in detail for
5891 <xref linkend="sql-select" endterm="sql-select-title">.
5992 </para>
6093 </refsect2>
6194
6295 <refsect2 id="R2-SQL-SELECTINTO-2">
6396 <refsect2info>
64- <date>1998-09-22 </date>
97+ <date>2001-03-20 </date>
6598 </refsect2info>
6699 <title>
67100 Outputs
68101 </title>
102+
69103 <para>
70- All output fields are described in detail for
71- <xref linkend="sql-select" endterm="sql-select-title">.
104+ Refer to
105+ <xref linkend="sql-createtable" endterm="sql-createtable-title">
106+ and
107+ <xref linkend="sql-select" endterm="sql-select-title">
108+ for a summary of possible output messages.
72109 </para>
73110 </refsect2>
74111 </refsynopsisdiv>
75112
76113 <refsect1 id="R1-SQL-SELECTINTO-1">
77114 <refsect1info>
78- <date>1998-09-22 </date>
115+ <date>2001-03-20 </date>
79116 </refsect1info>
80117 <title>
81118 Description
82119 </title>
120+
83121 <para>
84- <command>SELECT INTO</command> creates a new table from the results
85- of a query. Typically, this
86- query draws data from an existing table, but any SQL query is allowed.
122+ <command>SELECT INTO</command> creates a new table and fills it
123+ with data computed by a query. The data is not returned to the
124+ client, as it is with a normal <command>SELECT</command>. The new
125+ table's columns have the names and datatypes associated with the
126+ output columns of the <command>SELECT</command>.
87127
88128 <note>
89129 <para>
90130 <xref linkend="sql-createtableas" endterm="sql-createtableas-title">
91- is functionally equivalent to the <command>SELECT INTO</command> command.
131+ is functionally equivalent to <command>SELECT INTO</command>.
132+ <command>CREATE TABLE AS</command> is the recommended syntax, since
133+ <command>SELECT INTO</command> is not standard. In fact, this form of
134+ <command>SELECT INTO</command> is not available in PL/pgSQL or ecpg,
135+ because they interpret the INTO clause differently.
92136 </para>
93137 </note>
94138 </para>
95139 </refsect1>
140+
141+ <refsect1 id="R1-SQL-SELECTINTO-2">
142+ <title>
143+ Compatibility
144+ </title>
145+
146+ <para>
147+ SQL92 uses <command>SELECT ... INTO</command> to represent selecting
148+ values into scalar variables of a host program, rather than creating
149+ a new table. This indeed is the usage found in PL/pgSQL and ecpg.
150+ The <productname>Postgres</productname> usage of <command>SELECT
151+ INTO</command> to represent table creation is historical. It's best
152+ to use <command>CREATE TABLE AS</command> for this purpose in new code.
153+ (<command>CREATE TABLE AS</command> isn't standard either, but it's
154+ less likely to cause confusion.)
155+ </para>
156+ </refsect1>
96157</refentry>
97158
98159<!-- Keep this comment at the end of the file
0 commit comments