1
1
<!--
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 $
3
3
Postgres documentation
4
4
-->
5
5
@@ -15,7 +15,7 @@ Postgres documentation
15
15
SELECT INTO
16
16
</refname>
17
17
<refpurpose>
18
- Create a new table from an existing table or view
18
+ Creates a new table from the results of a SELECT
19
19
</refpurpose></refnamediv>
20
20
<refsynopsisdiv>
21
21
<refsynopsisdivinfo>
@@ -48,51 +48,112 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
48
48
49
49
<refsect2 id="R2-SQL-SELECTINTO-1">
50
50
<refsect2info>
51
- <date>1998-09-22 </date>
51
+ <date>2001-03-20 </date>
52
52
</refsect2info>
53
53
<title>
54
54
Inputs
55
55
</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
+
56
89
<para>
57
- All input fields are described in detail for
90
+ All other inputs are described in detail for
58
91
<xref linkend="sql-select" endterm="sql-select-title">.
59
92
</para>
60
93
</refsect2>
61
94
62
95
<refsect2 id="R2-SQL-SELECTINTO-2">
63
96
<refsect2info>
64
- <date>1998-09-22 </date>
97
+ <date>2001-03-20 </date>
65
98
</refsect2info>
66
99
<title>
67
100
Outputs
68
101
</title>
102
+
69
103
<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.
72
109
</para>
73
110
</refsect2>
74
111
</refsynopsisdiv>
75
112
76
113
<refsect1 id="R1-SQL-SELECTINTO-1">
77
114
<refsect1info>
78
- <date>1998-09-22 </date>
115
+ <date>2001-03-20 </date>
79
116
</refsect1info>
80
117
<title>
81
118
Description
82
119
</title>
120
+
83
121
<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>.
87
127
88
128
<note>
89
129
<para>
90
130
<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.
92
136
</para>
93
137
</note>
94
138
</para>
95
139
</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>
96
157
</refentry>
97
158
98
159
<!-- Keep this comment at the end of the file
0 commit comments