diff options
| author | Bruce Momjian | 2000-04-11 14:43:54 +0000 |
|---|---|---|
| committer | Bruce Momjian | 2000-04-11 14:43:54 +0000 |
| commit | f947bbb3b2ae270d0072aab85b538ba613e44054 (patch) | |
| tree | ec355a926d058d866e7a961cba6838a9d8178655 /doc/src/sgml | |
| parent | bdf6c4f0121c1251692196d730e588d29f17eb25 (diff) | |
Attached is are diffs for CREATE/ALTER table doc I've
forgotten in my mailbox (sorry). Haven't tried to apply and
since I don't have working sgml stuff cannot check.
Jan
Diffstat (limited to 'doc/src/sgml')
| -rw-r--r-- | doc/src/sgml/ref/alter_table.sgml | 43 | ||||
| -rw-r--r-- | doc/src/sgml/ref/create_table.sgml | 558 | ||||
| -rw-r--r-- | doc/src/sgml/ref/pg_dump.sgml | 12 |
3 files changed, 602 insertions, 11 deletions
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index ca302cf7987..8305f75d28e 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -1,5 +1,5 @@ <!-- -$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.11 2000/03/27 17:14:42 thomas Exp $ +$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.12 2000/04/11 14:43:54 momjian Exp $ Postgres documentation --> @@ -34,6 +34,8 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> [ * ] class="PARAMETER">newcolumn</replaceable> ALTER TABLE <replaceable class="PARAMETER">table</replaceable> RENAME TO <replaceable class="PARAMETER">newtable</replaceable> +ALTER TABLE <replaceable class="PARAMETER">table</replaceable> + ADD <replaceable class="PARAMETER">table constraint definition</replaceable> </synopsis> <refsect2 id="R2-SQL-ALTERTABLE-1"> @@ -89,6 +91,15 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> </para> </listitem> </varlistentry> + + <varlistentry> + <term><replaceable class="PARAMETER"> table constraint definition </replaceable></term> + <listitem> + <para> + New table constraint for the table + </para> + </listitem> + </varlistentry> </variablelist> </para> </refsect2> @@ -144,6 +155,9 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> the affected table. Thus, the table or column will remain of the same type and size after this command is executed. + The ADD <replaceable class="PARAMETER">table constraint definition</replaceable> clause + adds a new constraint to the table using the same syntax as <xref + linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title">. </para> <para> @@ -189,6 +203,16 @@ SELECT <replaceable>NewColumn</replaceable> FROM <replaceable>SuperClass</replac </para> <para> + In the current implementation, only FOREIGN KEY constraints can + be added to a table. To create or remove a unique constraint, create + a unique index (see <xref linkend="SQL-CREATEINDEX" + endterm="SQL-CREATEINDEX-title">). To add check constraints + you need to recreate and reload the table, using other + parameters to the <xref linkend="SQL-CREATETABLE" + endterm="SQL-CREATETABLE-title"> command. + </para> + + <para> You must own the class in order to change its schema. Renaming any part of the schema of a system catalog is not permitted. @@ -227,6 +251,13 @@ ALTER TABLE distributors RENAME COLUMN address TO city; ALTER TABLE distributors RENAME TO suppliers; </programlisting> </para> + + <para> + To add a foreign key constraint to a table: + <programlisting> +ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses(address) MATCH FULL + </programlisting> + </para> </refsect1> <refsect1 id="R1-SQL-ALTERTABLE-3"> @@ -253,17 +284,15 @@ ALTER TABLE distributors RENAME TO suppliers; <varlistentry> <term> <synopsis> -ALTER TABLE <replaceable class="PARAMETER">table</replaceable> ADD <replaceable class="PARAMETER">table constraint definition</replaceable> ALTER TABLE <replaceable class="PARAMETER">table</replaceable> DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> { RESTRICT | CASCADE } </synopsis> </term> <listitem> <para> - Adds or removes a table constraint (such as a check constraint, - unique constraint, or foreign key constraint). To create - or remove a unique constraint, create or drop a unique index, - respectively (see <xref linkend="SQL-CREATEINDEX" endterm="SQL-CREATEINDEX-title">). - To change other kinds of constraints you need to recreate + Removes a table constraint (such as a check constraint, + unique constraint, or foreign key constraint). To + remove a unique constraint, drop a unique index, + To remove other kinds of constraints you need to recreate and reload the table, using other parameters to the <xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title"> command. diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 56b722847a4..5102a2ad885 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -1,5 +1,5 @@ <!-- -$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.19 2000/04/08 02:44:55 momjian Exp $ +$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.20 2000/04/11 14:43:54 momjian Exp $ Postgres documentation --> @@ -450,7 +450,15 @@ CREATE TABLE distributors ( <synopsis> [ CONSTRAINT <replaceable class="parameter">name</replaceable> ] { [ NULL | NOT NULL ] | UNIQUE | PRIMARY KEY | CHECK <replaceable - class="parameter">constraint</replaceable> } [, ...] + class="parameter">constraint</replaceable> | REFERENCES + <replaceable class="parameter">referenced table</replaceable> + (<replaceable class="parameter">referenced column</replaceable>) + [ MATCH <replaceable class="parameter">match type</replaceable> ] + [ ON DELETE <replaceable class="parameter">action</replaceable> ] + [ ON UPDATE <replaceable class="parameter">action</replaceable> ] + [ [ NOT ] DEFERRABLE ] + [ INITIALLY <replaceable class="parameter"> check time </replaceable> ] } + [, ...] </synopsis> </para> @@ -900,7 +908,7 @@ ERROR: Cannot insert a duplicate key into a unique index. Only one PRIMARY KEY can be specified for a table. </para> </refsect3> - + <refsect3 id="R3-SQL-PRIMARYKEY-3"> <title> Notes @@ -920,6 +928,278 @@ ERROR: Cannot insert a duplicate key into a unique index. </para> </refsect3> </refsect2> + + <refsect2 id="R2-SQL-REFERENCES-1"> + <refsect2info> + <date>2000-02-04</date> + </refsect2info> + <title> + REFERENCES Constraint + </title> + <synopsis> +[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] REFERENCES +<replaceable class="parameter">referenced table</replaceable> [ ( <replaceable class="parameter"> referenced column</replaceable> ) ] +[ MATCH <replaceable class="parameter">matchtype</replaceable> ] +[ ON DELETE <replaceable class="parameter">action</replaceable> ] +[ ON UPDATE <replaceable class="parameter">action</replaceable> ] +[ [ NOT ] DEFERRABLE ] +[ INITIALLY <replaceable class="parameter"> check time </replaceable> ] + </synopsis> + <para> + The REFERENCES constraint specifies a rule that a column + value is checked against the values of another column. + REFERENCES can also be specified as part of + a FOREIGN KEY table constraint. + </para> + + <refsect3 id="R3-SQL-REFERENCES-1"> + <title>Inputs</title> + <para> + <variablelist> + <varlistentry> + <term>CONSTRAINT <replaceable class="PARAMETER">name</replaceable></term> + <listitem> + <para> + An arbitrary name for the constraint. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><replaceable class="parameter">referenced table</replaceable></term> + <listitem> + <para> + The table that contains the data to check against. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><replaceable class="parameter">referenced column</replaceable></term> + <listitem> + <para> + The column in the <replaceable class="parameter">referenced table</replaceable> + to check the data against. If this is not specified, the PRIMARY KEY of the + <replaceable class="parameter">referenced table</replaceable> is used. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>MATCH <replaceable class="parameter">matchtype</replaceable></term> + <listitem> + <para> + The type of comparison to do between the table data. There are three + types of matching, MATCH FULL, MATCH PARTIAL, and the unspecified match type + used if no match type is specified. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>ON DELETE <replaceable class="parameter">action</replaceable></term> + <listitem> + <para> + The action to do when a referenced row in the referenced table is being + deleted. There are the following actions. + <variablelist> + <varlistentry> + <term>CASCADE</term> + <listitem> + <para> + Delete any rows referencing the deleted row. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>RESTRICT</term> + <listitem> + <para> + Disallow deletion of rows being referenced. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>SET NULL</term> + <listitem> + <para> + Set the referencing column values to NULL. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>SET DEFAULT</term> + <listitem> + <para> + Set the referencing column values to their default value. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>NO ACTION</term> + <listitem> + <para> + Do nothing. + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>ON UPDATE <replaceable class="parameter">action</replaceable></term> + <listitem> + <para> + The action to do when a referenced column in the referenced table is being + updated to a new value. If the row is updated, but the referenced column + is not changed, no action is done. There are the following actions. + <variablelist> + <varlistentry> + <term>CASCADE</term> + <listitem> + <para> + Update the value of the referencing column to the new value of the + referenced column. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>RESTRICT</term> + <listitem> + <para> + Disallow update of row being referenced. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>SET NULL</term> + <listitem> + <para> + Set the referencing column values to NULL. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>SET DEFAULT</term> + <listitem> + <para> + Set the referencing column values to their default value. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>NO ACTION</term> + <listitem> + <para> + Do nothing. + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </listitem> + </varlistentry> + <varlistentry> + <term> [ NOT ] DEFERRABLE </term> + <listitem> + <para> + Tells the trigger manager whether this constraint may be + deferred to the end of transaction. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>INITIALLY <replaceable class="parameter"> check time </replaceable></term> + <listitem> + <para> + <replaceable class="parameter">check time</replaceable> has two possible values + which specify the default time to check the constraint. + <variablelist> + <varlistentry> + <term>DEFERRED</term> + <para> + Check this constraint at the end of the transaction. + </para> + </varlistentry> + <varlistentry> + <term>IMMEDIATE</term> + <para> + Check this constraint after each statement. + </para> + </varlistentry> + </variablelist> + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </refsect3> + + + <refsect3 id="R3-SQL-REFERENCES-2"> + <refsect3info> + <date>2000-02-04</date> + </refsect3info> + <title> + Outputs + </title> + <para> + <variablelist> + <varlistentry> + <term><replaceable>status</replaceable></term> + <listitem> + <para> + <variablelist> + <varlistentry> + <term><computeroutput> +ERROR: <replaceable class="parameter">name</replaceable> referential integrity violation - key referenced from +<replaceable class="parameter">table</replaceable> not found in <replaceable class="parameter">referenced table</replaceable> + </computeroutput></term> + <listitem> + <para> + This error occurs at runtime if one tries to insert a value + into a column which does not have a matching column in the + referenced table. + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </refsect3> + + <refsect3 id="R3-SQL-REFERENCES-3"> + <title>Description</title> + <para> + The REFERENCES column constraint specifies that a column of a + table must only contain values which match against values + in a referenced column of a referenced table. + </para> + <para> + A value added to this column are matched against the + values of the referenced table and referenced column using + the given match type. + In addition, when the referenced column data is changed, + actions are run upon this column's matching data. + </para> + </refsect3> + + <refsect3 id="R3-SQL-REFERENCES-4"> + <refsect3info> + <date>1998-09-11</date> + </refsect3info> + <title> + Notes + </title> + <para> + Currently <productname>Postgres</productname> only supports + MATCH FULL and an unspecified MATCH type. + In addition, the referenced columns are supposed to be + the columns of a UNIQUE constraint in the referenced table, + however <productname>Postgres</productname> does not + enforce this. + </para> + </refsect3> </refsect1> <refsect1 id="R1-SQL-TABLECONSTRAINT-1"> @@ -930,6 +1210,14 @@ ERROR: Cannot insert a duplicate key into a unique index. <synopsis> [ CONSTRAINT name ] { PRIMARY KEY | UNIQUE } ( <replaceable class="parameter">column</replaceable> [, ...] ) [ CONSTRAINT name ] CHECK ( <replaceable>constraint</replaceable> ) +[ CONSTRAINT name ] FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) + REFERENCES <replaceable class="parameter">referenced table</replaceable> + (<replaceable class="parameter">referenced column</replaceable> [, ...] ) + [ MATCH <match type> ] + [ ON DELETE <replaceable class="parameter">action</replaceable> ] + [ ON UPDATE <replaceable class="parameter">action</replaceable> ] + [ [ NOT ] DEFERRABLE ] + [ INITIALLY <replaceable class="parameter"> check time </replaceable> ] </synopsis> </para> <refsect2 id="R2-SQL-TABLECONSTRAINT-1"> @@ -1174,7 +1462,271 @@ CREATE TABLE distributors ( information. </para> </refsect3> + </refsect2> + <refsect2 id="R2-SQL-REFERENCES-1"> + <refsect2info> + <date>2000-02-04</date> + </refsect2info> + <title> + REFERENCES Constraint + </title> + <synopsis> +[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] +FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFERENCES +<replaceable class="parameter">referenced table</replaceable> [ ( <replaceable class="parameter">referenced column</replaceable> [, ...] ) ] +[ MATCH <replaceable class="parameter">matchtype</replaceable> ] +[ ON DELETE <replaceable class="parameter">action</replaceable> ] +[ ON UPDATE <replaceable class="parameter">action</replaceable> ] +[ [ NOT ] DEFERRABLE ] +[ INITIALLY <replaceable class="parameter"> check time </replaceable> ] + </synopsis> + <para> + The REFERENCES constraint specifies a rule that a column + value is checked against the values of another column. + REFERENCES can also be specified as part of + a FOREIGN KEY table constraint. + </para> + + <refsect3 id="R3-SQL-REFERENCES-1"> + <title>Inputs</title> + <para> + <variablelist> + <varlistentry> + <term>CONSTRAINT <replaceable class="PARAMETER">name</replaceable></term> + <listitem> + <para> + An arbitrary name for the constraint. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><replaceable class="PARAMETER">column</replaceable> [, ...]</term> + <listitem> + <para> + The names of one or more columns in the table. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><replaceable class="parameter">referenced table</replaceable></term> + <listitem> + <para> + The table that contains the data to check against. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><replaceable class="parameter">referenced column</replaceable> [, ...]</term> + <listitem> + <para> + One or more column in the <replaceable class="parameter">referenced table</replaceable> + to check the data against. If this is not specified, the PRIMARY KEY of the + <replaceable class="parameter">referenced table</replaceable> is used. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>MATCH <replaceable class="parameter">matchtype</replaceable></term> + <listitem> + <para> + The type of comparison to do between the table data. There are three + types of matching, MATCH FULL, MATCH PARTIAL, and the unspecified match type + used if no match type is specified. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>ON DELETE <replaceable class="parameter">action</replaceable></term> + <listitem> + <para> + The action to do when a referenced row in the referenced table is being + deleted. There are the following actions. + <variablelist> + <varlistentry> + <term>CASCADE</term> + <listitem> + <para> + Delete any rows referencing the deleted row. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>RESTRICT</term> + <listitem> + <para> + Disallow deletion of rows being referenced. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>SET NULL</term> + <listitem> + <para> + Set the referencing column values to NULL. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>SET DEFAULT</term> + <listitem> + <para> + Set the referencing column values to their default value. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>NO ACTION</term> + <listitem> + <para> + Do nothing. + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>ON UPDATE <replaceable class="parameter">action</replaceable></term> + <listitem> + <para> + The action to do when a referenced column in the referenced table is being + updated to a new value. If the row is updated, but the referenced column + is not changed, no action is done. There are the following actions. + <variablelist> + <varlistentry> + <term>CASCADE</term> + <listitem> + <para> + Update the value of the referencing column to the new value of the + referenced column. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>RESTRICT</term> + <listitem> + <para> + Disallow update of row being referenced. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>SET NULL</term> + <listitem> + <para> + Set the referencing column values to NULL. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>SET DEFAULT</term> + <listitem> + <para> + Set the referencing column values to their default value. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>NO ACTION</term> + <listitem> + <para> + Do nothing. + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </listitem> + </varlistentry> + <varlistentry> + <term> [ NOT ] DEFERRABLE </term> + <listitem> + <para> + Tells the trigger manager whether this constraint may be + deferred to the end of transaction. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term>INITIALLY <replaceable class="parameter"> check time </replaceable></term> + <listitem> + <para> + <replaceable class="parameter">check time</replaceable> has two possible values + which specify the default time to check the constraint. + <variablelist> + <varlistentry> + <term>DEFERRED</term> + <para> + Check this constraint at the end of the transaction. + </para> + </varlistentry> + <varlistentry> + <term>IMMEDIATE</term> + <para> + Check this constraint after each statement. + </para> + </varlistentry> + </variablelist> + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </refsect3> + <refsect3 id="R3-SQL-REFERENCES-2"> + <refsect3info> + <date>2000-02-04</date> + </refsect3info> + <title> + Outputs + </title> + <para> + <variablelist> + <varlistentry> + <term><replaceable>status</replaceable></term> + <listitem> + <para> + <variablelist> + <varlistentry> + <term><computeroutput> +ERROR: <replaceable class="parameter">name</replaceable> referential integrity violation - key referenced from +<replaceable class="parameter">table</replaceable> not found in <replaceable class="parameter">referenced table</replaceable> + </computeroutput></term> + <listitem> + <para> + This error occurs at runtime if one tries to insert a value + into a column which does not have a matching column in the + referenced table. + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </listitem> + </varlistentry> + </variablelist> + </para> + </refsect3> + <refsect3> + <title>Description</title> + <para> + The FOREIGN KEY constraint specifies a rule that a group of one + or more distinct columns of a table are related to a group + of distinct columns in the referenced table. + </para> + + <para> + The FOREIGN KEY table constraint is similar to that for column constraints, + with the additional capability of encompassing multiple columns. + </para> + <para> + Refer to the section on the FOREIGN KEY column constraint for more + information. + </para> + </refsect3> + </refsect2> </refsect1> diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index 14a986d6a49..401c41e4021 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -1,5 +1,5 @@ <!-- -$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.16 2000/04/04 05:22:45 tgl Exp $ +$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.17 2000/04/11 14:43:54 momjian Exp $ Postgres documentation --> @@ -362,6 +362,16 @@ dumpSequence(<replaceable class="parameter">table</replaceable>): SELECT failed Large objects are ignored and must be dealt with manually. </para> </listitem> + + <listitem> + <para> + When doing a data only dump, <application>pg_dump</application> emits queries + to disable triggers on user tables before inserting the data and queries to + reenable them after the data has been inserted. If the restore is stopped + in the middle, the system catalogs may be left in the wrong state. + </para> + </listitem> + </itemizedlist> </para> </refsect1> |
