3 PostgreSQL documentation
6 <refentry id=
"SQL-ALTERTABLE">
8 <refentrytitle id=
"sql-altertable-title">ALTER TABLE
</refentrytitle>
9 <manvolnum>7</manvolnum>
10 <refmiscinfo>SQL - Language Statements
</refmiscinfo>
14 <refname>ALTER TABLE
</refname>
15 <refpurpose>change the definition of a table
</refpurpose>
18 <indexterm zone=
"sql-altertable">
19 <primary>ALTER TABLE
</primary>
24 ALTER TABLE [ ONLY ]
<replaceable class=
"PARAMETER">name
</replaceable> [ * ]
25 <replaceable class=
"PARAMETER">action
</replaceable> [, ... ]
26 ALTER TABLE [ ONLY ]
<replaceable class=
"PARAMETER">name
</replaceable> [ * ]
27 RENAME [ COLUMN ]
<replaceable class=
"PARAMETER">column
</replaceable> TO
<replaceable class=
"PARAMETER">new_column
</replaceable>
28 ALTER TABLE
<replaceable class=
"PARAMETER">name
</replaceable>
29 RENAME TO
<replaceable class=
"PARAMETER">new_name
</replaceable>
30 ALTER TABLE
<replaceable class=
"PARAMETER">name
</replaceable>
31 SET SCHEMA
<replaceable class=
"PARAMETER">new_schema
</replaceable>
33 where
<replaceable class=
"PARAMETER">action
</replaceable> is one of:
35 ADD [ COLUMN ]
<replaceable class=
"PARAMETER">column
</replaceable> <replaceable class=
"PARAMETER">type
</replaceable> [
<replaceable class=
"PARAMETER">column_constraint
</replaceable> [ ... ] ]
36 DROP [ COLUMN ]
<replaceable class=
"PARAMETER">column
</replaceable> [ RESTRICT | CASCADE ]
37 ALTER [ COLUMN ]
<replaceable class=
"PARAMETER">column
</replaceable> [ SET DATA ] TYPE
<replaceable class=
"PARAMETER">type
</replaceable> [ USING
<replaceable class=
"PARAMETER">expression
</replaceable> ]
38 ALTER [ COLUMN ]
<replaceable class=
"PARAMETER">column
</replaceable> SET DEFAULT
<replaceable class=
"PARAMETER">expression
</replaceable>
39 ALTER [ COLUMN ]
<replaceable class=
"PARAMETER">column
</replaceable> DROP DEFAULT
40 ALTER [ COLUMN ]
<replaceable class=
"PARAMETER">column
</replaceable> { SET | DROP } NOT NULL
41 ALTER [ COLUMN ]
<replaceable class=
"PARAMETER">column
</replaceable> SET STATISTICS
<replaceable class=
"PARAMETER">integer
</replaceable>
42 ALTER [ COLUMN ]
<replaceable class=
"PARAMETER">column
</replaceable> SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
43 ADD
<replaceable class=
"PARAMETER">table_constraint
</replaceable>
44 DROP CONSTRAINT
<replaceable class=
"PARAMETER">constraint_name
</replaceable> [ RESTRICT | CASCADE ]
45 DISABLE TRIGGER [
<replaceable class=
"PARAMETER">trigger_name
</replaceable> | ALL | USER ]
46 ENABLE TRIGGER [
<replaceable class=
"PARAMETER">trigger_name
</replaceable> | ALL | USER ]
47 ENABLE REPLICA TRIGGER
<replaceable class=
"PARAMETER">trigger_name
</replaceable>
48 ENABLE ALWAYS TRIGGER
<replaceable class=
"PARAMETER">trigger_name
</replaceable>
49 DISABLE RULE
<replaceable class=
"PARAMETER">rewrite_rule_name
</replaceable>
50 ENABLE RULE
<replaceable class=
"PARAMETER">rewrite_rule_name
</replaceable>
51 ENABLE REPLICA RULE
<replaceable class=
"PARAMETER">rewrite_rule_name
</replaceable>
52 ENABLE ALWAYS RULE
<replaceable class=
"PARAMETER">rewrite_rule_name
</replaceable>
53 CLUSTER ON
<replaceable class=
"PARAMETER">index_name
</replaceable>
57 SET (
<replaceable class=
"PARAMETER">storage_parameter
</replaceable> =
<replaceable class=
"PARAMETER">value
</replaceable> [, ... ] )
58 RESET (
<replaceable class=
"PARAMETER">storage_parameter
</replaceable> [, ... ] )
59 INHERIT
<replaceable class=
"PARAMETER">parent_table
</replaceable>
60 NO INHERIT
<replaceable class=
"PARAMETER">parent_table
</replaceable>
61 OWNER TO
<replaceable class=
"PARAMETER">new_owner
</replaceable>
62 SET TABLESPACE
<replaceable class=
"PARAMETER">new_tablespace
</replaceable>
67 <title>Description
</title>
70 <command>ALTER TABLE
</command> changes the definition of an existing table.
71 There are several subforms:
75 <term><literal>ADD COLUMN
</literal></term>
78 This form adds a new column to the table, using the same syntax as
79 <xref linkend=
"SQL-CREATETABLE" endterm=
"SQL-CREATETABLE-TITLE">.
85 <term><literal>DROP COLUMN
</literal></term>
88 This form drops a column from a table. Indexes and
89 table constraints involving the column will be automatically
90 dropped as well. You will need to say
<literal>CASCADE<
/> if
91 anything outside the table depends on the column, for example,
92 foreign key references or views.
98 <term><literal>SET DATA TYPE
</literal></term>
101 This form changes the type of a column of a table. Indexes and
102 simple table constraints involving the column will be automatically
103 converted to use the new column type by reparsing the originally
104 supplied expression. The optional
<literal>USING
</literal>
105 clause specifies how to compute the new column value from the old;
106 if omitted, the default conversion is the same as an assignment
107 cast from old data type to new. A
<literal>USING
</literal>
108 clause must be provided if there is no implicit or assignment
109 cast from old to new type.
115 <term><literal>SET
</literal>/
<literal>DROP DEFAULT
</literal></term>
118 These forms set or remove the default value for a column.
119 The default values only apply to subsequent
<command>INSERT
</command>
120 commands; they do not cause rows already in the table to change.
121 Defaults can also be created for views, in which case they are
122 inserted into
<command>INSERT<
/> statements on the view before
123 the view's
<literal>ON INSERT
</literal> rule is applied.
129 <term><literal>SET
</literal>/
<literal>DROP NOT NULL
</literal></term>
132 These forms change whether a column is marked to allow null
133 values or to reject null values. You can only use
<literal>SET
134 NOT NULL<
/> when the column contains no null values.
140 <term><literal>SET STATISTICS
</literal></term>
144 sets the per-column statistics-gathering target for subsequent
145 <xref linkend=
"sql-analyze" endterm=
"sql-analyze-title"> operations.
146 The target can be set in the range
0 to
10000; alternatively, set it
147 to -
1 to revert to using the system default statistics
148 target (
<xref linkend=
"guc-default-statistics-target">).
149 For more information on the use of statistics by the
150 <productname>PostgreSQL
</productname> query planner, refer to
151 <xref linkend=
"planner-stats">.
158 <primary>TOAST
</primary>
159 <secondary>per-column storage settings
</secondary>
162 <term><literal>SET STORAGE
</literal></term>
165 This form sets the storage mode for a column. This controls whether this
166 column is held inline or in a supplementary table, and whether the data
167 should be compressed or not.
<literal>PLAIN
</literal> must be used
168 for fixed-length values such as
<type>integer
</type> and is
169 inline, uncompressed.
<literal>MAIN
</literal> is for inline,
170 compressible data.
<literal>EXTERNAL
</literal> is for external,
171 uncompressed data, and
<literal>EXTENDED
</literal> is for external,
172 compressed data.
<literal>EXTENDED
</literal> is the default for most
173 data types that support non-
<literal>PLAIN
</literal> storage.
174 Use of
<literal>EXTERNAL
</literal> will
175 make substring operations on
<type>text
</type> and
<type>bytea
</type>
176 columns faster, at the penalty of increased storage space. Note that
177 <literal>SET STORAGE<
/> doesn't itself change anything in the table,
178 it just sets the strategy to be pursued during future table updates.
179 See
<xref linkend=
"storage-toast"> for more information.
185 <term><literal>ADD
<replaceable class=
"PARAMETER">table_constraint
</replaceable></literal></term>
188 This form adds a new constraint to a table using the same syntax as
189 <xref linkend=
"SQL-CREATETABLE" endterm=
"SQL-CREATETABLE-TITLE">.
195 <term><literal>DROP CONSTRAINT
</literal></term>
198 This form drops the specified constraint on a table.
204 <term><literal>DISABLE
</literal>/
<literal>ENABLE [ REPLICA | ALWAYS ] TRIGGER
</literal></term>
207 These forms configure the firing of trigger(s) belonging to the table.
208 A disabled trigger is still known to the system, but is not executed
209 when its triggering event occurs. For a deferred trigger, the enable
210 status is checked when the event occurs, not when the trigger function
211 is actually executed. One can disable or enable a single
212 trigger specified by name, or all triggers on the table, or only
213 user triggers (this option excludes triggers that are used to implement
214 foreign key constraints). Disabling or enabling constraint triggers
215 requires superuser privileges; it should be done with caution since
216 of course the integrity of the constraint cannot be guaranteed if the
217 triggers are not executed.
218 The trigger firing mechanism is also affected by the configuration
219 variable
<xref linkend=
"guc-session-replication-role">. Simply enabled
220 triggers will fire when the replication role is
<quote>origin<
/>
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.
230 <term><literal>DISABLE
</literal>/
<literal>ENABLE [ REPLICA | ALWAYS ] RULE
</literal></term>
233 These forms configure the firing of rewrite rules belonging to the table.
234 A disabled rule is still known to the system, but is not applied
235 during query rewriting. The semantics are as for disabled/enabled
236 triggers. This configuration is ignored for
<literal>ON SELECT
</literal> rules, which
237 are always applied in order to keep views working even if the current
238 session is in a non-default replication role.
244 <term><literal>CLUSTER
</literal></term>
247 This form selects the default index for future
248 <xref linkend=
"SQL-CLUSTER" endterm=
"sql-cluster-title">
249 operations. It does not actually re-cluster the table.
255 <term><literal>SET WITHOUT CLUSTER
</literal></term>
258 This form removes the most recently used
259 <xref linkend=
"SQL-CLUSTER" endterm=
"sql-cluster-title">
260 index specification from the table. This affects
261 future cluster operations that don't specify an index.
267 <term><literal>SET WITH OIDS
</literal></term>
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.
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.
284 <term><literal>SET WITHOUT OIDS
</literal></term>
287 This form removes the
<literal>oid
</literal> system column from the
288 table. This is exactly equivalent to
289 <literal>DROP COLUMN oid RESTRICT
</literal>,
290 except that it will not complain if there is already no
291 <literal>oid
</literal> column.
297 <term><literal>SET (
<replaceable class=
"PARAMETER">storage_parameter
</replaceable> =
<replaceable class=
"PARAMETER">value
</replaceable> [, ... ] )
</literal></term>
300 This form changes one or more storage parameters for the table. See
301 <xref linkend=
"SQL-CREATETABLE-storage-parameters"
302 endterm=
"sql-createtable-storage-parameters-title">
303 for details on the available parameters. Note that the table contents
304 will not be modified immediately by this command; depending on the
305 parameter you might need to rewrite the table to get the desired effects.
306 That can be done with
<xref linkend=
"SQL-CLUSTER"
307 endterm=
"sql-cluster-title"> or one of the forms of
<command>ALTER
308 TABLE<
/> that forces a table rewrite.
313 While
<command>CREATE TABLE<
/> allows
<literal>OIDS<
/> to be specified
314 in the
<literal>WITH (
<replaceable
315 class=
"PARAMETER">storage_parameter<
/>)
</literal> syntax,
316 <command>ALTER TABLE<
/> does not treat
<literal>OIDS<
/> as a
317 storage parameter. Instead use the
<literal>SET WITH OIDS<
/>
318 and
<literal>SET WITHOUT OIDS<
/> forms to change OID status.
325 <term><literal>RESET (
<replaceable class=
"PARAMETER">storage_parameter
</replaceable> [, ... ] )
</literal></term>
328 This form resets one or more storage parameters to their
329 defaults. As with
<literal>SET<
/>, a table rewrite might be
330 needed to update the table entirely.
336 <term><literal>INHERIT
<replaceable class=
"PARAMETER">parent_table
</replaceable></literal></term>
339 This form adds the target table as a new child of the specified parent
340 table. Subsequently, queries against the parent will include records
341 of the target table. To be added as a child, the target table must
342 already contain all the same columns as the parent (it could have
343 additional columns, too). The columns must have matching data types,
344 and if they have
<literal>NOT NULL
</literal> constraints in the parent
345 then they must also have
<literal>NOT NULL
</literal> constraints in the
350 There must also be matching child-table constraints for all
351 <literal>CHECK
</literal> constraints of the parent. Currently
352 <literal>UNIQUE
</literal>,
<literal>PRIMARY KEY
</literal>, and
353 <literal>FOREIGN KEY
</literal> constraints are not considered, but
354 this might change in the future.
360 <term><literal>NO INHERIT
<replaceable class=
"PARAMETER">parent_table
</replaceable></literal></term>
363 This form removes the target table from the list of children of the
364 specified parent table.
365 Queries against the parent table will no longer include records drawn
366 from the target table.
372 <term><literal>OWNER
</literal></term>
375 This form changes the owner of the table, sequence, or view to the
382 <term><literal>SET TABLESPACE
</literal></term>
385 This form changes the table's tablespace to the specified tablespace and
386 moves the data file(s) associated with the table to the new tablespace.
387 Indexes on the table, if any, are not moved; but they can be moved
388 separately with additional
<literal>SET TABLESPACE
</literal> commands.
390 <xref linkend=
"SQL-CREATETABLESPACE" endterm=
"sql-createtablespace-title">.
396 <term><literal>RENAME
</literal></term>
399 The
<literal>RENAME
</literal> forms change the name of a table
400 (or an index, sequence, or view) or the name of an individual column in
401 a table. There is no effect on the stored data.
407 <term><literal>SET SCHEMA
</literal></term>
410 This form moves the table into another schema. Associated indexes,
411 constraints, and sequences owned by table columns are moved as well.
420 All the actions except
<literal>RENAME
</literal> and
<literal>SET SCHEMA<
/>
422 a list of multiple alterations to apply in parallel. For example, it
423 is possible to add several columns and/or alter the type of several
424 columns in a single command. This is particularly useful with large
425 tables, since only one pass over the table need be made.
429 You must own the table to use
<command>ALTER TABLE<
/>.
430 To change the schema of a table, you must also have
431 <literal>CREATE
</literal> privilege on the new schema.
432 To add the table as a new child of a parent table, you must own the
433 parent table as well.
434 To alter the owner, you must also be a direct or indirect member of the new
435 owning role, and that role must have
<literal>CREATE
</literal> privilege on
436 the table's schema. (These restrictions enforce that altering the owner
437 doesn't do anything you couldn't do by dropping and recreating the table.
438 However, a superuser can alter ownership of any table anyway.)
443 <title>Parameters
</title>
448 <term><replaceable class=
"PARAMETER">name
</replaceable></term>
451 The name (possibly schema-qualified) of an existing table to
452 alter. If
<literal>ONLY<
/> is specified, only that table is
453 altered. If
<literal>ONLY<
/> is not specified, the table and any
454 descendant tables are altered.
460 <term><replaceable class=
"PARAMETER">column
</replaceable></term>
463 Name of a new or existing column.
469 <term><replaceable class=
"PARAMETER">new_column
</replaceable></term>
472 New name for an existing column.
478 <term><replaceable class=
"PARAMETER">new_name
</replaceable></term>
481 New name for the table.
487 <term><replaceable class=
"PARAMETER">type
</replaceable></term>
490 Data type of the new column, or new data type for an existing
497 <term><replaceable class=
"PARAMETER">table_constraint
</replaceable></term>
500 New table constraint for the table.
506 <term><replaceable class=
"PARAMETER">constraint_name
</replaceable></term>
509 Name of an existing constraint to drop.
515 <term><literal>CASCADE
</literal></term>
518 Automatically drop objects that depend on the dropped column
519 or constraint (for example, views referencing the column).
525 <term><literal>RESTRICT
</literal></term>
528 Refuse to drop the column or constraint if there are any dependent
529 objects. This is the default behavior.
535 <term><replaceable class=
"PARAMETER">trigger_name
</replaceable></term>
538 Name of a single trigger to disable or enable.
544 <term><literal>ALL
</literal></term>
547 Disable or enable all triggers belonging to the table.
548 (This requires superuser privilege if any of the triggers are for
549 foreign key constraints.)
555 <term><literal>USER
</literal></term>
558 Disable or enable all triggers belonging to the table except for
559 foreign key constraint triggers.
565 <term><replaceable class=
"PARAMETER">index_name
</replaceable></term>
568 The index name on which the table should be marked for clustering.
574 <term><replaceable class=
"PARAMETER">storage_parameter
</replaceable></term>
577 The name of a table storage parameter.
583 <term><replaceable class=
"PARAMETER">value
</replaceable></term>
586 The new value for a table storage parameter.
587 This might be a number or a word depending on the parameter.
593 <term><replaceable class=
"PARAMETER">parent_table
</replaceable></term>
596 A parent table to associate or de-associate with this table.
602 <term><replaceable class=
"PARAMETER">new_owner
</replaceable></term>
605 The user name of the new owner of the table.
611 <term><replaceable class=
"PARAMETER">new_tablespace
</replaceable></term>
614 The name of the tablespace to which the table will be moved.
620 <term><replaceable class=
"PARAMETER">new_schema
</replaceable></term>
623 The name of the schema to which the table will be moved.
635 The key word
<literal>COLUMN
</literal> is noise and can be omitted.
639 When a column is added with
<literal>ADD COLUMN
</literal>, all existing
640 rows in the table are initialized with the column's default value
641 (NULL if no
<literal>DEFAULT<
/> clause is specified).
645 Adding a column with a non-null default or changing the type of an
646 existing column will require the entire table to be rewritten. This
647 might take a significant amount of time for a large table; and it will
648 temporarily require double the disk space. Adding or removing a system
649 <literal>oid<
/> column likewise requires rewriting the entire table.
653 Adding a
<literal>CHECK<
/> or
<literal>NOT NULL<
/> constraint requires
654 scanning the table to verify that existing rows meet the constraint.
658 The main reason for providing the option to specify multiple changes
659 in a single
<command>ALTER TABLE<
/> is that multiple table scans or
660 rewrites can thereby be combined into a single pass over the table.
664 The
<literal>DROP COLUMN
</literal> form does not physically remove
665 the column, but simply makes it invisible to SQL operations. Subsequent
666 insert and update operations in the table will store a null value for the
667 column. Thus, dropping a column is quick but it will not immediately
668 reduce the on-disk size of your table, as the space occupied
669 by the dropped column is not reclaimed. The space will be
670 reclaimed over time as existing rows are updated. (These statements do
671 not apply when dropping the system
<literal>oid<
/> column; that is done
672 with an immediate rewrite.)
676 The fact that
<literal>ALTER TYPE<
/> requires rewriting the whole table
677 is sometimes an advantage, because the rewriting process eliminates
678 any dead space in the table. For example, to reclaim the space occupied
679 by a dropped column immediately, the fastest way is:
681 ALTER TABLE table ALTER COLUMN anycol TYPE anytype;
683 where
<literal>anycol<
/> is any remaining table column and
684 <literal>anytype<
/> is the same type that column already has.
685 This results in no semantically-visible change in the table,
686 but the command forces rewriting, which gets rid of no-longer-useful
691 The
<literal>USING
</literal> option of
<literal>ALTER TYPE<
/> can actually
692 specify any expression involving the old values of the row; that is, it
693 can refer to other columns as well as the one being converted. This allows
694 very general conversions to be done with the
<literal>ALTER TYPE<
/>
695 syntax. Because of this flexibility, the
<literal>USING
</literal>
696 expression is not applied to the column's default value (if any); the
697 result might not be a constant expression as required for a default.
698 This means that when there is no implicit or assignment cast from old to
699 new type,
<literal>ALTER TYPE<
/> might fail to convert the default even
700 though a
<literal>USING
</literal> clause is supplied. In such cases,
701 drop the default with
<literal>DROP DEFAULT<
/>, perform the
<literal>ALTER
702 TYPE<
/>, and then use
<literal>SET DEFAULT<
/> to add a suitable new
703 default. Similar considerations apply to indexes and constraints involving
708 If a table has any descendant tables, it is not permitted to add,
709 rename, or change the type of a column in the parent table without doing
710 the same to the descendants. That is,
<command>ALTER TABLE ONLY
</command>
711 will be rejected. This ensures that the descendants always have
712 columns matching the parent.
716 A recursive
<literal>DROP COLUMN
</literal> operation will remove a
717 descendant table's column only if the descendant does not inherit
718 that column from any other parents and never had an independent
719 definition of the column. A nonrecursive
<literal>DROP
720 COLUMN
</literal> (i.e.,
<command>ALTER TABLE ONLY ... DROP
721 COLUMN
</command>) never removes any descendant columns, but
722 instead marks them as independently defined rather than inherited.
726 The
<literal>TRIGGER<
/>,
<literal>CLUSTER<
/>,
<literal>OWNER<
/>,
727 and
<literal>TABLESPACE<
/> actions never recurse to descendant tables;
728 that is, they always act as though
<literal>ONLY<
/> were specified.
729 Adding a constraint can recurse only for
<literal>CHECK<
/> constraints,
730 and is required to do so for such constraints.
734 Changing any part of a system catalog table is not permitted.
738 Refer to
<xref linkend=
"sql-createtable"
739 endterm=
"sql-createtable-title"> for a further description of valid
740 parameters.
<xref linkend=
"ddl"> has further information on
746 <title>Examples
</title>
749 To add a column of type
<type>varchar
</type> to a table:
751 ALTER TABLE distributors ADD COLUMN address varchar(
30);
756 To drop a column from a table:
758 ALTER TABLE distributors DROP COLUMN address RESTRICT;
763 To change the types of two existing columns in one operation:
765 ALTER TABLE distributors
766 ALTER COLUMN address TYPE varchar(
80),
767 ALTER COLUMN name TYPE varchar(
100);
772 To change an integer column containing UNIX timestamps to
<type>timestamp
773 with time zone
</type> via a
<literal>USING
</literal> clause:
776 ALTER COLUMN foo_timestamp SET DATA TYPE timestamp with time zone
778 timestamp with time zone 'epoch' + foo_timestamp * interval '
1 second';
783 The same, when the column has a default expression that won't automatically
784 cast to the new data type:
787 ALTER COLUMN foo_timestamp DROP DEFAULT,
788 ALTER COLUMN foo_timestamp TYPE timestamp with time zone
790 timestamp with time zone 'epoch' + foo_timestamp * interval '
1 second',
791 ALTER COLUMN foo_timestamp SET DEFAULT now();
796 To rename an existing column:
798 ALTER TABLE distributors RENAME COLUMN address TO city;
803 To rename an existing table:
805 ALTER TABLE distributors RENAME TO suppliers;
810 To add a not-null constraint to a column:
812 ALTER TABLE distributors ALTER COLUMN street SET NOT NULL;
814 To remove a not-null constraint from a column:
816 ALTER TABLE distributors ALTER COLUMN street DROP NOT NULL;
821 To add a check constraint to a table and all its children:
823 ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) =
5);
828 To remove a check constraint from a table and all its children:
830 ALTER TABLE distributors DROP CONSTRAINT zipchk;
835 To remove a check constraint from a table only:
837 ALTER TABLE ONLY distributors DROP CONSTRAINT zipchk;
839 (The check constraint remains in place for any child tables.)
843 To add a foreign key constraint to a table:
845 ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address) MATCH FULL;
850 To add a (multicolumn) unique constraint to a table:
852 ALTER TABLE distributors ADD CONSTRAINT dist_id_zipcode_key UNIQUE (dist_id, zipcode);
857 To add an automatically named primary key constraint to a table, noting
858 that a table can only ever have one primary key:
860 ALTER TABLE distributors ADD PRIMARY KEY (dist_id);
865 To move a table to a different tablespace:
867 ALTER TABLE distributors SET TABLESPACE fasttablespace;
872 To move a table to a different schema:
874 ALTER TABLE myschema.distributors SET SCHEMA yourschema;
881 <title>Compatibility
</title>
884 The forms
<literal>ADD
</literal>,
<literal>DROP<
/>,
<literal>SET DEFAULT<
/>,
885 and
<literal>SET DATA TYPE
</literal> (without
<literal>USING
</literal>)
886 conform with the SQL standard. The other forms are
887 <productname>PostgreSQL
</productname> extensions of the SQL standard.
888 Also, the ability to specify more than one manipulation in a single
889 <command>ALTER TABLE<
/> command is an extension.
893 <command>ALTER TABLE DROP COLUMN<
/> can be used to drop the only
894 column of a table, leaving a zero-column table. This is an
895 extension of SQL, which disallows zero-column tables.