1
1
<!--
2
- $PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.103 2009/02/09 20:57:59 alvherre Exp $
2
+ $PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.104 2009/02/11 21:11:15 tgl Exp $
3
3
PostgreSQL documentation
4
4
-->
5
5
@@ -52,6 +52,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
52
52
ENABLE ALWAYS RULE <replaceable class="PARAMETER">rewrite_rule_name</replaceable>
53
53
CLUSTER ON <replaceable class="PARAMETER">index_name</replaceable>
54
54
SET WITHOUT CLUSTER
55
+ SET WITH OIDS
55
56
SET WITHOUT OIDS
56
57
SET ( <replaceable class="PARAMETER">storage_parameter</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )
57
58
RESET ( <replaceable class="PARAMETER">storage_parameter</replaceable> [, ... ] )
@@ -185,7 +186,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
185
186
<listitem>
186
187
<para>
187
188
This form adds a new constraint to a table using the same syntax as
188
- <xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
189
+ <xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
189
190
</para>
190
191
</listitem>
191
192
</varlistentry>
@@ -217,10 +218,10 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
217
218
The trigger firing mechanism is also affected by the configuration
218
219
variable <xref linkend="guc-session-replication-role">. Simply enabled
219
220
triggers will fire when the replication role is <quote>origin</>
220
- (the default) or <quote>local</>. Triggers configured <literal>ENABLE REPLICA</ literal>
221
- will only fire if the session is in <quote>replica</> mode and triggers
222
- configured <literal>ENABLE ALWAYS</literal> will fire regardless of the current replication
223
- mode.
221
+ (the default) or <quote>local</>. Triggers configured as < literal>ENABLE
222
+ REPLICA</literal> will only fire if the session is in <quote>replica</>
223
+ mode, and triggers configured as <literal>ENABLE ALWAYS</literal> will
224
+ fire regardless of the current replication mode.
224
225
</para>
225
226
</listitem>
226
227
</varlistentry>
@@ -243,7 +244,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
243
244
<term><literal>CLUSTER</literal></term>
244
245
<listitem>
245
246
<para>
246
- This form selects the default index for future
247
+ This form selects the default index for future
247
248
<xref linkend="SQL-CLUSTER" endterm="sql-cluster-title">
248
249
operations. It does not actually re-cluster the table.
249
250
</para>
@@ -262,6 +263,23 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
262
263
</listitem>
263
264
</varlistentry>
264
265
266
+ <varlistentry>
267
+ <term><literal>SET WITH OIDS</literal></term>
268
+ <listitem>
269
+ <para>
270
+ This form adds an <literal>oid</literal> system column to the
271
+ table (see <xref linkend="ddl-system-columns">).
272
+ It does nothing if the table already has OIDs.
273
+ </para>
274
+
275
+ <para>
276
+ Note that this is not equivalent to <literal>ADD COLUMN oid oid</>;
277
+ that would add a normal column that happened to be named
278
+ <literal>oid</>, not a system column.
279
+ </para>
280
+ </listitem>
281
+ </varlistentry>
282
+
265
283
<varlistentry>
266
284
<term><literal>SET WITHOUT OIDS</literal></term>
267
285
<listitem>
@@ -272,12 +290,6 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
272
290
except that it will not complain if there is already no
273
291
<literal>oid</literal> column.
274
292
</para>
275
-
276
- <para>
277
- Note that there is no variant of <command>ALTER TABLE</command>
278
- that allows OIDs to be restored to a table once they have been
279
- removed.
280
- </para>
281
293
</listitem>
282
294
</varlistentry>
283
295
@@ -302,7 +314,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
302
314
in the <literal>WITH (<replaceable
303
315
class="PARAMETER">storage_parameter</>)</literal> syntax,
304
316
<command>ALTER TABLE</> does not treat <literal>OIDS</> as a
305
- storage parameter.
317
+ storage parameter. Instead use the <literal>SET WITH OIDS</>
318
+ and <literal>SET WITHOUT OIDS</> forms to change OID status.
306
319
</para>
307
320
</note>
308
321
</listitem>
@@ -373,7 +386,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
373
386
moves the data file(s) associated with the table to the new tablespace.
374
387
Indexes on the table, if any, are not moved; but they can be moved
375
388
separately with additional <literal>SET TABLESPACE</literal> commands.
376
- See also
389
+ See also
377
390
<xref linkend="SQL-CREATETABLESPACE" endterm="sql-createtablespace-title">.
378
391
</para>
379
392
</listitem>
@@ -637,7 +650,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
637
650
Adding a column with a non-null default or changing the type of an
638
651
existing column will require the entire table to be rewritten. This
639
652
might take a significant amount of time for a large table; and it will
640
- temporarily require double the disk space.
653
+ temporarily require double the disk space. Adding or removing a system
654
+ <literal>oid</> column likewise requires rewriting the entire table.
641
655
</para>
642
656
643
657
<para>
@@ -656,9 +670,11 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
656
670
the column, but simply makes it invisible to SQL operations. Subsequent
657
671
insert and update operations in the table will store a null value for the
658
672
column. Thus, dropping a column is quick but it will not immediately
659
- reduce the on-disk size of your table, as the space occupied
673
+ reduce the on-disk size of your table, as the space occupied
660
674
by the dropped column is not reclaimed. The space will be
661
- reclaimed over time as existing rows are updated.
675
+ reclaimed over time as existing rows are updated. (These statements do
676
+ not apply when dropping the system <literal>oid</> column; that is done
677
+ with an immediate rewrite.)
662
678
</para>
663
679
664
680
<para>
@@ -806,58 +822,58 @@ ALTER TABLE distributors ALTER COLUMN street DROP NOT NULL;
806
822
</programlisting>
807
823
</para>
808
824
809
- <para>
825
+ <para>
810
826
To add a check constraint to a table and all its children:
811
827
<programlisting>
812
828
ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5);
813
829
</programlisting>
814
830
</para>
815
831
816
- <para>
832
+ <para>
817
833
To remove a check constraint from a table and all its children:
818
834
<programlisting>
819
835
ALTER TABLE distributors DROP CONSTRAINT zipchk;
820
836
</programlisting>
821
837
</para>
822
838
823
- <para>
839
+ <para>
824
840
To remove a check constraint from a table only:
825
841
<programlisting>
826
842
ALTER TABLE ONLY distributors DROP CONSTRAINT zipchk;
827
843
</programlisting>
828
844
(The check constraint remains in place for any child tables.)
829
845
</para>
830
846
831
- <para>
847
+ <para>
832
848
To add a foreign key constraint to a table:
833
849
<programlisting>
834
850
ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address) MATCH FULL;
835
851
</programlisting>
836
852
</para>
837
853
838
- <para>
854
+ <para>
839
855
To add a (multicolumn) unique constraint to a table:
840
856
<programlisting>
841
857
ALTER TABLE distributors ADD CONSTRAINT dist_id_zipcode_key UNIQUE (dist_id, zipcode);
842
858
</programlisting>
843
859
</para>
844
860
845
- <para>
861
+ <para>
846
862
To add an automatically named primary key constraint to a table, noting
847
863
that a table can only ever have one primary key:
848
864
<programlisting>
849
865
ALTER TABLE distributors ADD PRIMARY KEY (dist_id);
850
866
</programlisting>
851
867
</para>
852
868
853
- <para>
869
+ <para>
854
870
To move a table to a different tablespace:
855
871
<programlisting>
856
872
ALTER TABLE distributors SET TABLESPACE fasttablespace;
857
873
</programlisting>
858
874
</para>
859
875
860
- <para>
876
+ <para>
861
877
To move a table to a different schema:
862
878
<programlisting>
863
879
ALTER TABLE myschema.distributors SET SCHEMA yourschema;
0 commit comments