mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Here is my much-promised patch to let people add UNIQUE constraints after
table creation time. Big deal you say - but this patch is the basis of the next thing which is adding PRIMARY KEYs after table creation time. (Which is currently impossible without twiddling catalogs) Rundown ------- * I have made the makeObjectName function of analyze.c non-static, and exported it in analyze.h * I have included analyze.h and defrem.h into command.c, to support makingObjectNames and creating indices * I removed the 'case CONSTR_PRIMARY' clause so that it properly fails and says you can't add primary keys, rather than just doing nothing and reporting nothing!!! * I have modified the docs. Algorithm --------- * If name specified is null, search for a new valid constraint name. I'm not sure if I should "lock" my generated name somehow tho - should I open the relation before doing this step? * Open relation in access exclusive mode * Check that the constraint does not already exist * Define the new index * Warn if they're doubling up on an existing index Christopher Kings-Lynne
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.26 2001/09/03 12:57:49 petere Exp $
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.27 2001/09/07 21:57:53 momjian Exp $
|
||||
Postgres documentation
|
||||
-->
|
||||
|
||||
@ -211,9 +211,9 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
In the current implementation, only FOREIGN KEY and CHECK constraints can
|
||||
be added to a table. To create a unique constraint, create
|
||||
a unique index (see <xref linkend="SQL-CREATEINDEX"
|
||||
In the current implementation, only UNIQUE, FOREIGN KEY and CHECK constraints can
|
||||
be added to a table. To create a primary constraint, create
|
||||
a unique, not null index (see <xref linkend="SQL-CREATEINDEX"
|
||||
endterm="SQL-CREATEINDEX-title">).
|
||||
</para>
|
||||
|
||||
@ -297,6 +297,13 @@ ALTER TABLE distributors DROP CONSTRAINT zipchk
|
||||
ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses(address) MATCH FULL
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
To add a (multi-column) unique constraint to a table:
|
||||
<programlisting>
|
||||
ALTER TABLE distributors ADD CONSTRAINT dist_id_zipcode_key UNIQUE (dist_id, zipcode)
|
||||
</programlisting>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 id="R1-SQL-ALTERTABLE-3">
|
||||
|
Reference in New Issue
Block a user