11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.42 2002/04/21 19: 02:39 thomas Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.43 2002/04/23 02:07:15 tgl Exp $
33PostgreSQL documentation
44-->
55
@@ -24,23 +24,22 @@ PostgreSQL documentation
2424ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ * ]
2525 ADD [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> <replaceable class="PARAMETER">type</replaceable> [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
2626ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ * ]
27- ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> { SET DEFAULT <replaceable
28- class="PARAMETER">value</replaceable> | DROP DEFAULT }
27+ ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> { SET DEFAULT <replaceable class="PARAMETER">value</replaceable> | DROP DEFAULT }
2928ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ * ]
3029 ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> { SET | DROP } NOT NULL
3130ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ * ]
3231 ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET STATISTICS <replaceable class="PARAMETER">integer</replaceable>
3332ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ * ]
34- ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET STORAGE {PLAIN | EXTERNAL | EXTENDED | MAIN}
33+ ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
3534ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ * ]
3635 RENAME [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> TO <replaceable
37- class="PARAMETER">newcolumn </replaceable>
36+ class="PARAMETER">new_column </replaceable>
3837ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
3938 RENAME TO <replaceable class="PARAMETER">new_table</replaceable>
4039ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
4140 ADD <replaceable class="PARAMETER">table_constraint_definition</replaceable>
4241ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable>
43- DROP CONSTRAINT <replaceable class="PARAMETER">constraint </replaceable> { RESTRICT | CASCADE }
42+ DROP CONSTRAINT <replaceable class="PARAMETER">constraint_name </replaceable> { RESTRICT | CASCADE }
4443ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
4544OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
4645 </synopsis>
@@ -58,7 +57,7 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
5857 <term><replaceable class="PARAMETER"> table </replaceable></term>
5958 <listitem>
6059 <para>
61- The name of an existing table to alter.
60+ The name(possibly schema-qualified) of an existing table to alter.
6261 </para>
6362 </listitem>
6463 </varlistentry>
@@ -82,7 +81,7 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
8281 </varlistentry>
8382
8483 <varlistentry>
85- <term><replaceable class="PARAMETER">newcolumn </replaceable></term>
84+ <term><replaceable class="PARAMETER">new_column </replaceable></term>
8685 <listitem>
8786 <para>
8887New name for an existing column.
@@ -103,7 +102,16 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
103102 <term><replaceable class="PARAMETER"> table_constraint_definition </replaceable></term>
104103 <listitem>
105104 <para>
106- New table constraint for the table
105+ New table constraint for the table.
106+ </para>
107+ </listitem>
108+ </varlistentry>
109+
110+ <varlistentry>
111+ <term><replaceable class="PARAMETER"> constraint_name </replaceable></term>
112+ <listitem>
113+ <para>
114+ Name of an existing constraint to drop.
107115 </para>
108116 </listitem>
109117 </varlistentry>
@@ -162,44 +170,124 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
162170 </title>
163171 <para>
164172 <command>ALTER TABLE</command> changes the definition of an existing table.
165- The <literal>ADD COLUMN</literal> form adds a new column to the table
166- using the same syntax as <xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
167- The <literal>ALTER COLUMN SET/DROP DEFAULT</literal> forms
168- allow you to set or remove the default for the column. Note that defaults
169- only apply to subsequent <command>INSERT</command> commands; they do not
170- cause rows already in the table to change.
171- The <literal>ALTER COLUMN SET/DROP NOT NULL</literal> forms allow you to
172- change whether a column is marked to allow NULL values or to reject NULL
173- values.
174- The <literal>ALTER COLUMN SET STATISTICS</literal> form allows you to
175- set the statistics-gathering target for subsequent
176- <xref linkend="sql-analyze" endterm="sql-analyze-title"> operations.
177- The <literal>ALTER COLUMN SET STORAGE</literal> form allows the
178- column storage mode to be set. This controls whether this column is
179- held inline or in a supplementary table, and whether the data
180- should be compressed or not. <literal>PLAIN</literal> must be used
181- for fixed-length values such as <literal>INTEGER</literal> and is
182- inline, uncompressed. <literal>MAIN</literal> is for inline,
183- compressible data. <literal>EXTERNAL</literal> is for external,
184- uncompressed data and <literal>EXTENDED</literal> is for external,
185- compressed data. The use of <literal>EXTERNAL</literal> will make
186- substring operations on a column faster, at the penalty of
187- increased storage space.
188- The <literal>RENAME</literal> clause causes the name of a table,
189- column, index, sequence or view to change without changing any of the
190- data. The data will remain of the same type and size after the
191- command is executed.
192- The ADD <replaceable class="PARAMETER">table_constraint_definition</replaceable> clause
193- adds a new constraint to the table using the same syntax as <xref
194- linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
195- The DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> clause
196- drops all constraints on the table (and its children) that match <replaceable class="PARAMETER">constraint</replaceable>.
197- The OWNER clause changes the owner of the table, index, sequence or view to the
198- user <replaceable class="PARAMETER">new user</replaceable>.
173+ There are several sub-forms:
199174 </para>
200175
176+ <variablelist>
177+
178+ <varlistentry>
179+ <term>ADD COLUMN</term>
180+ <listitem>
181+ <para>
182+ This form adds a new column to the table using the same syntax as
183+ <xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
184+ </para>
185+ </listitem>
186+ </varlistentry>
187+
188+ <varlistentry>
189+ <term>SET/DROP DEFAULT</term>
190+ <listitem>
191+ <para>
192+ These forms set or remove the default value for a column. Note
193+ that defaults only apply to subsequent <command>INSERT</command>
194+ commands; they do not cause rows already in the table to change.
195+ Defaults may also be created for views, in which case they are
196+ inserted into <command>INSERT</> statements on the view before
197+ the view's ON INSERT rule is applied.
198+ </para>
199+ </listitem>
200+ </varlistentry>
201+
202+ <varlistentry>
203+ <term>SET/DROP NOT NULL</term>
204+ <listitem>
205+ <para>
206+ These forms change whether a column is marked to allow NULL
207+ values or to reject NULL values. You may only <literal>SET NOT NULL</>
208+ when the table contains no NULLs in the column.
209+ </para>
210+ </listitem>
211+ </varlistentry>
212+
213+ <varlistentry>
214+ <term>SET STATISTICS</term>
215+ <listitem>
216+ <para>
217+ This form
218+ sets the per-column statistics-gathering target for subsequent
219+ <xref linkend="sql-analyze" endterm="sql-analyze-title"> operations.
220+ </para>
221+ </listitem>
222+ </varlistentry>
223+
224+ <varlistentry>
225+ <term>SET STORAGE</term>
226+ <listitem>
227+ <para>
228+ This form sets the storage mode for a column. This controls whether this
229+ column is held inline or in a supplementary table, and whether the data
230+ should be compressed or not. <literal>PLAIN</literal> must be used
231+ for fixed-length values such as <literal>INTEGER</literal> and is
232+ inline, uncompressed. <literal>MAIN</literal> is for inline,
233+ compressible data. <literal>EXTERNAL</literal> is for external,
234+ uncompressed data and <literal>EXTENDED</literal> is for external,
235+ compressed data. <literal>EXTENDED</literal> is the default for all
236+ datatypes that support it. The use of <literal>EXTERNAL</literal> will
237+ make substring operations on a TEXT column faster, at the penalty of
238+ increased storage space.
239+ </para>
240+ </listitem>
241+ </varlistentry>
242+
243+ <varlistentry>
244+ <term>RENAME</term>
245+ <listitem>
246+ <para>
247+ The <literal>RENAME</literal> forms change the name of a table
248+ (or an index, sequence, or view) or the name of an individual column in
249+ a table. There is no effect on the stored data.
250+ </para>
251+ </listitem>
252+ </varlistentry>
253+
254+ <varlistentry>
255+ <term>ADD <replaceable class="PARAMETER">table_constraint_definition</replaceable></term>
256+ <listitem>
257+ <para>
258+ This form adds a new constraint to a table using the same syntax as
259+ <xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
260+ </para>
261+ </listitem>
262+ </varlistentry>
263+
264+ <varlistentry>
265+ <term>DROP CONSTRAINT</term>
266+ <listitem>
267+ <para>
268+ This form drops constraints on a table (and its children).
269+ Currently, constraints on tables are not required to have unique
270+ names, so there may be more than one constraint matching the specified
271+ name. All such constraints will be dropped.
272+ </para>
273+ </listitem>
274+ </varlistentry>
275+
276+ <varlistentry>
277+ <term>OWNER</term>
278+ <listitem>
279+ <para>
280+ This form changes the owner of the table, index, sequence or view to the
281+ specified user.
282+ </para>
283+ </listitem>
284+ </varlistentry>
285+
286+ </variablelist>
287+
201288 <para>
202- You must own the table in order to change its schema.
289+ You must own the table to use <command>ALTER TABLE</>; except for
290+ <command>ALTER TABLE OWNER</>, which may only be executed by a superuser.
203291 </para>
204292
205293 <refsect2 id="R2-SQL-ALTERTABLE-3">
@@ -216,16 +304,20 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
216304 <para>
217305 In the current implementation of <literal>ADD COLUMN</literal>,
218306 default and NOT NULL clauses for the new column are not supported.
307+ The new column always comes into being with all values NULL.
219308 You can use the <literal>SET DEFAULT</literal> form
220- of <command>ALTER TABLE</command> to set the defaultlater .
309+ of <command>ALTER TABLE</command> to set the defaultafterwards .
221310 (You may also want to update the already existing rows to the
222- new default value, using <xref linkend="sql-update" endterm="sql-update-title">.)
311+ new default value, using
312+ <xref linkend="sql-update" endterm="sql-update-title">.)
313+ If you want to mark the column non-null, use the <literal>SET NOT NULL</>
314+ form after you've entered non-null values for the column in all rows.
223315 </para>
224316
225317 <para>
226318 In DROP CONSTRAINT, the RESTRICT keyword is required, although
227319 dependencies are not yet checked. The CASCADE option is unsupported.
228- Currently DROP CONSTRAINTdrops only CHECK constraints.
320+ Currently DROP CONSTRAINT only handles CHECK constraints.
229321 To remove a PRIMARY or UNIQUE constraint, drop the
230322 relevant index using the <xref linkend="SQL-DROPINDEX" endterm="sql-dropindex-title"> command.
231323 To remove FOREIGN KEY constraints you need to recreate
@@ -243,16 +335,15 @@ DROP TABLE temp;
243335 </para>
244336
245337 <para>
246- You must own the table in order to change it.
247338 Changing any part of the schema of a system
248339 catalog is not permitted.
249- The <citetitle>PostgreSQL User's Guide</citetitle> has further
250- information on inheritance.
251340 </para>
252341
253342 <para>
254343 Refer to <command>CREATE TABLE</command> for a further description
255344 of valid arguments.
345+ The <citetitle>PostgreSQL User's Guide</citetitle> has further
346+ information on inheritance.
256347 </para>
257348 </refsect2>
258349 </refsect1>