Commit 6787c6c9 authored by Bruce Momjian's avatar Bruce Momjian

Updates create_function.sgml with fixes for new foreign keys

parent 91cce19d
TODO list for PostgreSQL TODO list for PostgreSQL
======================== ========================
Last updated: Thu Mar 23 01:35:33 EST 2000 Last updated: Fri Apr 14 16:07:41 EDT 2000
Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us) Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
...@@ -309,6 +309,7 @@ SOURCE CODE ...@@ -309,6 +309,7 @@ SOURCE CODE
* Remove SET KSQO option if OR processing is improved(Tom) * Remove SET KSQO option if OR processing is improved(Tom)
* -Pre-generate lex and yacc output so not required for install(Peter E) * -Pre-generate lex and yacc output so not required for install(Peter E)
* Use macros to define NT open() file parameters, remove NT-specific defines * Use macros to define NT open() file parameters, remove NT-specific defines
* Change CURRENT to OLD internally for rules
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.22 2000/04/13 07:19:27 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.23 2000/04/14 21:44:21 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -97,15 +97,16 @@ CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table</replacea ...@@ -97,15 +97,16 @@ CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table</replacea
<term><replaceable>column_constraint_clause</replaceable></term> <term><replaceable>column_constraint_clause</replaceable></term>
<listitem> <listitem>
<para> <para>
The optional column constraint clauses specify a list of integrity The optional column constraint clauses specify a list of
constraints or tests which new or updated entries must satisfy for integrity constraints or tests which new or updated entries must
an insert or update operation to succeed. Each constraint satisfy for an insert or update operation to succeed. Each
must evaluate to a boolean expression. Although <acronym>SQL92</acronym> constraint must evaluate to a boolean expression. Although
requires the <replaceable class="PARAMETER">column_constraint_clause</replaceable> <acronym>SQL92</acronym> requires the <replaceable
to refer to that column only, <productname>Postgres</productname> class="PARAMETER">column_constraint_clause</replaceable> to
allows multiple columns refer to that column only, <productname>Postgres</productname>
to be referenced within a single column constraint. allows multiple columns to be referenced within a single column
See the column constraint clause for more information. constraint. See the column constraint clause for more
information.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -114,16 +115,16 @@ CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table</replacea ...@@ -114,16 +115,16 @@ CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table</replacea
<term><replaceable>table_constraint_clause</replaceable></term> <term><replaceable>table_constraint_clause</replaceable></term>
<listitem> <listitem>
<para> <para>
The optional table CONSTRAINT clause specifies a list of integrity The optional table CONSTRAINT clause specifies a
constraints which new or updated entries must satisfy for list of integrity constraints which new or updated entries must
an insert or update operation to succeed. Each constraint satisfy for an insert or update operation to succeed. Each
must evaluate to a boolean expression. Multiple columns constraint must evaluate to a boolean expression. Multiple
may be referenced within a single constraint. columns may be referenced within a single constraint. Only one
Only one PRIMARY KEY clause may be specified for a table; PRIMARY KEY clause may be specified for a table;
PRIMARY KEY <replaceable>column</replaceable> PRIMARY KEY <replaceable>column</replaceable> (a table
(a table constraint) and PRIMARY KEY (a column constraint) are constraint) and PRIMARY KEY (a column constraint)
mutually exclusive.. are mutually exclusive.. See the table constraint clause for
See the table constraint clause for more information. more information.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -140,13 +141,6 @@ CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table</replacea ...@@ -140,13 +141,6 @@ CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table</replacea
<productname>Postgres</productname> automatically allows the created <productname>Postgres</productname> automatically allows the created
table to inherit functions on tables above it in the inheritance table to inherit functions on tables above it in the inheritance
hierarchy. hierarchy.
<note>
<title>Aside</title>
<para>
Inheritance of functions is done according
to the conventions of the Common Lisp Object System (CLOS).
</para>
</note>
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -227,7 +221,7 @@ ERROR: DEFAULT: type mismatched ...@@ -227,7 +221,7 @@ ERROR: DEFAULT: type mismatched
<para> <para>
<note> <note>
<para> <para>
As of Postgres version 6.0, consistant array dimensions within an As of Postgres version 6.0, consistent array dimensions within an
attribute are not enforced. This will likely change in a future attribute are not enforced. This will likely change in a future
release. release.
</para> </para>
...@@ -353,13 +347,13 @@ DEFAULT <replaceable class="PARAMETER">value</replaceable> ...@@ -353,13 +347,13 @@ DEFAULT <replaceable class="PARAMETER">value</replaceable>
<varlistentry> <varlistentry>
<term>SESSION_USER</term> <term>SESSION_USER</term>
<listitem> <listitem>
<simpara>not yet supported</simpara> <simpara>See CURRENT_USER function</simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>SYSTEM_USER</term> <term>SYSTEM_USER</term>
<listitem> <listitem>
<simpara>not yet supported</simpara> <simpara>See CURRENT_USER function</simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>
...@@ -502,9 +496,9 @@ CREATE TABLE distributors ( ...@@ -502,9 +496,9 @@ CREATE TABLE distributors (
<listitem> <listitem>
<para> <para>
This column is a primary key, which implies that uniqueness is This column is a primary key, which implies that uniqueness is
enforced by the system and that other tables may rely on this column enforced by the system and that other tables may rely on this
as a unique identifier for rows. column as a unique identifier for rows. See PRIMARY KEY for more
See PRIMARY KEY for more information. information.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -529,13 +523,12 @@ CREATE TABLE distributors ( ...@@ -529,13 +523,12 @@ CREATE TABLE distributors (
</title> </title>
<para> <para>
The optional constraint The optional constraint clauses specify constraints or tests which
clauses specify constraints or tests which new or updated entries new or updated entries must satisfy for an insert or update
must satisfy for an insert or update operation to succeed. Each constraint operation to succeed. Each constraint must evaluate to a boolean
must evaluate to a boolean expression. Multiple attributes may be referenced within expression. Multiple attributes may be referenced within a single
a single constraint. The use of PRIMARY KEY constraint. The use of PRIMARY KEY as a table constraint is mutually
as a table constraint incompatible with PRIMARY KEY as a column constraint.
is mutually incompatible with PRIMARY KEY as a column constraint.
</para> </para>
<para> <para>
...@@ -550,10 +543,9 @@ CREATE TABLE distributors ( ...@@ -550,10 +543,9 @@ CREATE TABLE distributors (
</para> </para>
<para> <para>
A column constraint is an integrity constraint defined as part A column constraint is an integrity constraint defined as part of a
of a column definition, and logically becomes a table column definition, and logically becomes a table constraint as soon
constraint as soon as it is created. The column as it is created. The column constraints available are:
constraints available are:
<simplelist columns="1"> <simplelist columns="1">
<member>PRIMARY KEY</member> <member>PRIMARY KEY</member>
...@@ -563,14 +555,6 @@ CREATE TABLE distributors ( ...@@ -563,14 +555,6 @@ CREATE TABLE distributors (
<member>NOT NULL</member> <member>NOT NULL</member>
</simplelist> </simplelist>
</para> </para>
<note>
<para>
<productname>Postgres</productname> now
(new for v7.0) supports
REFERENCES integrity constraints.
</para>
</note>
</refsect2> </refsect2>
<refsect2 id="R2-SQL-NOTNULL-1"> <refsect2 id="R2-SQL-NOTNULL-1">
...@@ -711,10 +695,10 @@ ERROR: Cannot insert a duplicate key into a unique index. ...@@ -711,10 +695,10 @@ ERROR: Cannot insert a duplicate key into a unique index.
The column definitions of the specified columns do not have to The column definitions of the specified columns do not have to
include a NOT NULL constraint to be included in a UNIQUE include a NOT NULL constraint to be included in a UNIQUE
constraint. Having more than one null value in a column without a constraint. Having more than one null value in a column without a
NOT NULL constraint, does not violate a UNIQUE constraint. NOT NULL constraint, does not violate a UNIQUE constraint. (This
(This deviates from the <acronym>SQL92</acronym> definition, but deviates from the <acronym>SQL92</acronym> definition, but is a
is a more sensible convention. See the section on compatibility more sensible convention. See the section on compatibility for more
for more details.). details.).
</para> </para>
<para> <para>
Each UNIQUE column constraint must name a column that is Each UNIQUE column constraint must name a column that is
...@@ -827,14 +811,13 @@ ERROR: ExecAppend: rejected due to CHECK constraint "<replaceable class="parame ...@@ -827,14 +811,13 @@ ERROR: ExecAppend: rejected due to CHECK constraint "<replaceable class="parame
<title>Description</title> <title>Description</title>
<para> <para>
The CHECK constraint specifies a restriction on allowed values The CHECK constraint specifies a restriction on allowed values
within a column. within a column. The CHECK constraint is also allowed as a table
The CHECK constraint is also allowed as a table constraint. constraint.
</para> </para>
<para> <para>
The SQL92 CHECK column constraints can only be defined on, and The SQL92 CHECK column constraints can only be defined on, and
refer to, one column of the table. <productname>Postgres</productname> refer to, one column of the table.
does not have <productname>Postgres</productname> does not have this restriction.
this restriction.
</para> </para>
</refsect3> </refsect3>
</refsect2> </refsect2>
...@@ -883,11 +866,11 @@ ERROR: Cannot insert a duplicate key into a unique index. ...@@ -883,11 +866,11 @@ ERROR: Cannot insert a duplicate key into a unique index.
<refsect3> <refsect3>
<title>Description</title> <title>Description</title>
<para> <para>
The PRIMARY KEY column constraint specifies that a column of a table The PRIMARY KEY column constraint specifies that a column of a
may contain only unique table may contain only unique (non-duplicate), non-NULL values. The
(non-duplicate), non-NULL values. The definition of definition of the specified column does not have to include an
the specified column does not have to include an explicit NOT NULL explicit NOT NULL constraint to be included in a PRIMARY KEY
constraint to be included in a PRIMARY KEY constraint. constraint.
</para> </para>
<para> <para>
Only one PRIMARY KEY can be specified for a table. Only one PRIMARY KEY can be specified for a table.
...@@ -974,9 +957,11 @@ ERROR: Cannot insert a duplicate key into a unique index. ...@@ -974,9 +957,11 @@ ERROR: Cannot insert a duplicate key into a unique index.
<term>MATCH <replaceable class="parameter">matchtype</replaceable></term> <term>MATCH <replaceable class="parameter">matchtype</replaceable></term>
<listitem> <listitem>
<para> <para>
The type of comparison to do between the table data. There are three The type of comparison to do between the table data. There are
types of matching, MATCH FULL, MATCH PARTIAL, and the unspecified match type three types of matching, MATCH FULL, MATCH PARTIAL, and the
used if no match type is specified. unspecified match type used if no match type is specified.
MATCH PARTIAL is not
currently supported.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -988,10 +973,10 @@ ERROR: Cannot insert a duplicate key into a unique index. ...@@ -988,10 +973,10 @@ ERROR: Cannot insert a duplicate key into a unique index.
deleted. There are the following actions. deleted. There are the following actions.
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>CASCADE</term> <term>NO ACTION</term>
<listitem> <listitem>
<para> <para>
Delete any rows referencing the deleted row. Produce error if foreign key violated. This is the default.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -999,31 +984,31 @@ ERROR: Cannot insert a duplicate key into a unique index. ...@@ -999,31 +984,31 @@ ERROR: Cannot insert a duplicate key into a unique index.
<term>RESTRICT</term> <term>RESTRICT</term>
<listitem> <listitem>
<para> <para>
Disallow deletion of rows being referenced. Same as NO ACTION.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>SET NULL</term> <term>CASCADE</term>
<listitem> <listitem>
<para> <para>
Set the referencing column values to NULL. Delete any rows referencing the deleted row.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>SET DEFAULT</term> <term>SET NULL</term>
<listitem> <listitem>
<para> <para>
Set the referencing column values to their default value. Set the referencing column values to NULL.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>NO ACTION</term> <term>SET DEFAULT</term>
<listitem> <listitem>
<para> <para>
Do nothing. Set the referencing column values to their default value.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1035,16 +1020,16 @@ ERROR: Cannot insert a duplicate key into a unique index. ...@@ -1035,16 +1020,16 @@ ERROR: Cannot insert a duplicate key into a unique index.
<term>ON UPDATE <replaceable class="parameter">action</replaceable></term> <term>ON UPDATE <replaceable class="parameter">action</replaceable></term>
<listitem> <listitem>
<para> <para>
The action to do when a referenced column in the referenced table is being The action to do when a referenced column in the referenced
updated to a new value. If the row is updated, but the referenced column table is being updated to a new value. If the row is updated,
is not changed, no action is done. There are the following actions. but the referenced column is not changed, no action is done.
There are the following actions.
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>CASCADE</term> <term>NO ACTION</term>
<listitem> <listitem>
<para> <para>
Update the value of the referencing column to the new value of the Produce error if foreign key violated. This is the default.
referenced column.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1052,31 +1037,32 @@ ERROR: Cannot insert a duplicate key into a unique index. ...@@ -1052,31 +1037,32 @@ ERROR: Cannot insert a duplicate key into a unique index.
<term>RESTRICT</term> <term>RESTRICT</term>
<listitem> <listitem>
<para> <para>
Disallow update of row being referenced. Same as NO ACTION.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>SET NULL</term> <term>CASCADE</term>
<listitem> <listitem>
<para> <para>
Set the referencing column values to NULL. Update the value of the referencing column to the new value of the
referenced column.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>SET DEFAULT</term> <term>SET NULL</term>
<listitem> <listitem>
<para> <para>
Set the referencing column values to their default value. Set the referencing column values to NULL.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>NO ACTION</term> <term>SET DEFAULT</term>
<listitem> <listitem>
<para> <para>
Do nothing. Set the referencing column values to their default value.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1089,8 +1075,10 @@ ERROR: Cannot insert a duplicate key into a unique index. ...@@ -1089,8 +1075,10 @@ ERROR: Cannot insert a duplicate key into a unique index.
<term> [ NOT ] DEFERRABLE </term> <term> [ NOT ] DEFERRABLE </term>
<listitem> <listitem>
<para> <para>
Tells the trigger manager whether this constraint may be This controls whether the constraint can be deferred to the end
deferred to the end of transaction. of the transaction. If DEFERRABLE, SET CONSTRAINTS ALL DEFERRED
will cause the foreign key to be checked only at the end of the
transaction. NOT DEFERRABLE is the default.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1101,22 +1089,20 @@ ERROR: Cannot insert a duplicate key into a unique index. ...@@ -1101,22 +1089,20 @@ ERROR: Cannot insert a duplicate key into a unique index.
<para> <para>
<replaceable class="parameter">checktime</replaceable> has two possible values <replaceable class="parameter">checktime</replaceable> has two possible values
which specify the default time to check the constraint. which specify the default time to check the constraint.
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>DEFERRED</term> <term>DEFERRED</term>
<listitem> <listitem>
<para> <para>
Check this constraint at the end of the transaction. Check constraint only at the end of the transaction.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>IMMEDIATE</term> <term>IMMEDIATE</term>
<listitem> <listitem>
<para> <para>
Check this constraint after each statement. Check constraint after each statement. This is the default.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1167,16 +1153,15 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity ...@@ -1167,16 +1153,15 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity
<refsect3 id="R3-SQL-REFERENCES-3"> <refsect3 id="R3-SQL-REFERENCES-3">
<title>Description</title> <title>Description</title>
<para> <para>
The REFERENCES column constraint specifies that a column of a The REFERENCES column constraint specifies that a
table must only contain values which match against values column of a table must only contain values which match against
in a referenced column of a referenced table. values in a referenced column of a referenced table.
</para> </para>
<para> <para>
A value added to this column are matched against the A value added to this column are matched against the values of the
values of the referenced table and referenced column using referenced table and referenced column using the given match type.
the given match type. In addition, when the referenced column data is changed, actions
In addition, when the referenced column data is changed, are run upon this column's matching data.
actions are run upon this column's matching data.
</para> </para>
</refsect3> </refsect3>
...@@ -1188,12 +1173,11 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity ...@@ -1188,12 +1173,11 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity
Notes Notes
</title> </title>
<para> <para>
Currently <productname>Postgres</productname> only supports Currently <productname>Postgres</productname> only supports MATCH
MATCH FULL and an unspecified match type. FULL and an unspecified match type. In addition, the referenced
In addition, the referenced columns are supposed to be columns are supposed to be the columns of a UNIQUE constraint in
the columns of a UNIQUE constraint in the referenced table, the referenced table, however <productname>Postgres</productname>
however <productname>Postgres</productname> does not does not enforce this.
enforce this.
</para> </para>
</refsect3> </refsect3>
</refsect2> </refsect2>
...@@ -1281,14 +1265,6 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity ...@@ -1281,14 +1265,6 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity
<member>FOREIGN KEY</member> <member>FOREIGN KEY</member>
</simplelist> </simplelist>
</para> </para>
<note>
<para>
<productname>Postgres</productname> now
supports FOREIGN KEY
integrity constraints
</para>
</note>
</refsect2> </refsect2>
<refsect2 id="R2-SQL-UNIQUECLAUSE-4"> <refsect2 id="R2-SQL-UNIQUECLAUSE-4">
...@@ -1354,10 +1330,11 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity ...@@ -1354,10 +1330,11 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity
</title> </title>
<para> <para>
The UNIQUE constraint specifies a rule that a group of one or The UNIQUE constraint specifies a rule that a group of one or more
more distinct columns of a table may contain only unique values. distinct columns of a table may contain only unique values. The
The behavior of the UNIQUE table constraint is the same as that for column behavior of the UNIQUE table constraint is the same as that for
constraints, with the additional capability to span multiple columns. column constraints, with the additional capability to span multiple
columns.
</para> </para>
<para> <para>
See the section on the UNIQUE column constraint for more details. See the section on the UNIQUE column constraint for more details.
...@@ -1428,8 +1405,8 @@ CREATE TABLE distributors ( ...@@ -1428,8 +1405,8 @@ CREATE TABLE distributors (
<term>ERROR: Cannot insert a duplicate key into a unique index.</term> <term>ERROR: Cannot insert a duplicate key into a unique index.</term>
<listitem> <listitem>
<para> <para>
This occurs at run-time if one tries to insert a duplicate value into This occurs at run-time if one tries to insert a duplicate
a column subject to a PRIMARY KEY constraint. value into a column subject to a PRIMARY KEY constraint.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1479,10 +1456,9 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE ...@@ -1479,10 +1456,9 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE
[ INITIALLY <replaceable class="parameter">checktime</replaceable> ] [ INITIALLY <replaceable class="parameter">checktime</replaceable> ]
</synopsis> </synopsis>
<para> <para>
The REFERENCES constraint specifies a rule that a column The REFERENCES constraint specifies a rule that a column value is
value is checked against the values of another column. checked against the values of another column. REFERENCES can also be
REFERENCES can also be specified as part of specified as part of a FOREIGN KEY table constraint.
a FOREIGN KEY table constraint.
</para> </para>
<refsect3 id="R3-SQL-REFERENCES-5"> <refsect3 id="R3-SQL-REFERENCES-5">
...@@ -1527,9 +1503,10 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE ...@@ -1527,9 +1503,10 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE
<term>MATCH <replaceable class="parameter">matchtype</replaceable></term> <term>MATCH <replaceable class="parameter">matchtype</replaceable></term>
<listitem> <listitem>
<para> <para>
The type of comparison to do between the table data. There are three The type of comparison to do between the table data. There are
types of matching, MATCH FULL, MATCH PARTIAL, and the unspecified match type three types of matching, MATCH FULL, MATCH PARTIAL, and the
used if no match type is specified. unspecified match type used if no match type is specified.
MATCH PARTIAL is not currently supported.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1541,10 +1518,10 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE ...@@ -1541,10 +1518,10 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE
deleted. There are the following actions. deleted. There are the following actions.
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>CASCADE</term> <term>NO ACTION</term>
<listitem> <listitem>
<para> <para>
Delete any rows referencing the deleted row. Produce error if foreign key violated. This is the default.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1552,31 +1529,31 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE ...@@ -1552,31 +1529,31 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE
<term>RESTRICT</term> <term>RESTRICT</term>
<listitem> <listitem>
<para> <para>
Disallow deletion of rows being referenced. Same as NO ACTION.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>SET NULL</term> <term>CASCADE</term>
<listitem> <listitem>
<para> <para>
Set the referencing column values to NULL. Delete any rows referencing the deleted row.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>SET DEFAULT</term> <term>SET NULL</term>
<listitem> <listitem>
<para> <para>
Set the referencing column values to their default value. Set the referencing column values to NULL.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>NO ACTION</term> <term>SET DEFAULT</term>
<listitem> <listitem>
<para> <para>
Do nothing. Set the referencing column values to their default value.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1588,16 +1565,16 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE ...@@ -1588,16 +1565,16 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE
<term>ON UPDATE <replaceable class="parameter">action</replaceable></term> <term>ON UPDATE <replaceable class="parameter">action</replaceable></term>
<listitem> <listitem>
<para> <para>
The action to do when a referenced column in the referenced table is being The action to do when a referenced column in the referenced
updated to a new value. If the row is updated, but the referenced column table is being updated to a new value. If the row is updated,
is not changed, no action is done. There are the following actions. but the referenced column is not changed, no action is done.
There are the following actions.
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>CASCADE</term> <term>NO ACTION</term>
<listitem> <listitem>
<para> <para>
Update the value of the referencing column to the new value of the Produce error if foreign key violated. This is the default.
referenced column.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1610,26 +1587,27 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE ...@@ -1610,26 +1587,27 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>SET NULL</term> <term>CASCADE</term>
<listitem> <listitem>
<para> <para>
Set the referencing column values to NULL. Update the value of the referencing column to the new value
of the referenced column.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>SET DEFAULT</term> <term>SET NULL</term>
<listitem> <listitem>
<para> <para>
Set the referencing column values to their default value. Set the referencing column values to NULL.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>NO ACTION</term> <term>SET DEFAULT</term>
<listitem> <listitem>
<para> <para>
Do nothing. Set the referencing column values to their default value.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1641,8 +1619,10 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE ...@@ -1641,8 +1619,10 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE
<term> [ NOT ] DEFERRABLE </term> <term> [ NOT ] DEFERRABLE </term>
<listitem> <listitem>
<para> <para>
Tells the trigger manager whether this constraint may be This controls whether the constraint can be deferred to the end
deferred to the end of transaction. of the transaction. If DEFERRABLE, SET CONSTRAINTS ALL DEFERRED
will cause the foreign key to be checked only at the end of the
transaction. NOT DEFERRABLE is the default.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1650,22 +1630,23 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE ...@@ -1650,22 +1630,23 @@ FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ...] ) REFE
<term>INITIALLY <replaceable class="parameter">checktime</replaceable></term> <term>INITIALLY <replaceable class="parameter">checktime</replaceable></term>
<listitem> <listitem>
<para> <para>
<replaceable class="parameter">checktime</replaceable> has two possible values <replaceable class="parameter">checktime</replaceable> has two
which specify the default time to check the constraint. possible values which specify the default time to check the
constraint.
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>DEFERRED</term> <term>IMMEDIATE</term>
<listitem> <listitem>
<para> <para>
Check this constraint at the end of the transaction. Check constraint after each statement. This is the default.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>IMMEDIATE</term> <term>DEFERRED</term>
<listitem> <listitem>
<para> <para>
Check this constraint after each statement. Check constraint only at the end of the transaction.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1719,8 +1700,9 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity ...@@ -1719,8 +1700,9 @@ ERROR: <replaceable class="parameter">name</replaceable> referential integrity
</para> </para>
<para> <para>
The FOREIGN KEY table constraint is similar to that for column constraints, The FOREIGN KEY table constraint is similar to that for column
with the additional capability of encompassing multiple columns. constraints, with the additional capability of encompassing
multiple columns.
</para> </para>
<para> <para>
Refer to the section on the FOREIGN KEY column constraint for more Refer to the section on the FOREIGN KEY column constraint for more
...@@ -1886,10 +1868,10 @@ CREATE GLOBAL TEMPORARY TABLE <replaceable class="parameter">table</replaceable> ...@@ -1886,10 +1868,10 @@ CREATE GLOBAL TEMPORARY TABLE <replaceable class="parameter">table</replaceable>
constraints. constraints.
</para> </para>
<para> <para>
The optional ON COMMIT clause of CREATE TEMPORARY TABLE The optional ON COMMIT clause of CREATE TEMPORARY TABLE specifies
specifies whether or not the temporary table should be emptied of whether or not the temporary table should be emptied of rows
rows whenever COMMIT is executed. If the ON COMMIT clause is whenever COMMIT is executed. If the ON COMMIT clause is omitted, the
omitted, the default option, ON COMMIT DELETE ROWS, is assumed. default option, ON COMMIT DELETE ROWS, is assumed.
</para> </para>
<para> <para>
To create a temporary table: To create a temporary table:
...@@ -1936,10 +1918,10 @@ CREATE TEMPORARY TABLE actors ( ...@@ -1936,10 +1918,10 @@ CREATE TEMPORARY TABLE actors (
NULL clause NULL clause
</title> </title>
<para> <para>
The NULL "constraint" (actually a non-constraint) The NULL "constraint" (actually a non-constraint) is a
is a <productname>Postgres</productname> extension to SQL92 <productname>Postgres</productname> extension to SQL92 is
is included for symmetry with the NOT NULL clause. Since it is the default included for symmetry with the NOT NULL clause. Since it is the
for any column, its presence is simply noise. default for any column, its presence is simply noise.
<synopsis> <synopsis>
[ CONSTRAINT name ] NULL [ CONSTRAINT name ] NULL
</synopsis> </synopsis>
...@@ -2001,11 +1983,10 @@ the column. Not our problem... ...@@ -2001,11 +1983,10 @@ the column. Not our problem...
</para> </para>
<para> <para>
An assertion is a special type of integrity constraint and share An assertion is a special type of integrity constraint and share
the same namespace as other constraints. the same namespace as other constraints. However, an assertion is
However, an assertion is not necessarily dependent on one not necessarily dependent on one particular base table as
particular base table as constraints are, so SQL-92 provides the constraints are, so SQL-92 provides the CREATE ASSERTION statement
CREATE ASSERTION statement as an alternate method for defining a as an alternate method for defining a constraint:
constraint:
</para> </para>
<synopsis> <synopsis>
CREATE ASSERTION name CHECK ( condition ) CREATE ASSERTION name CHECK ( condition )
...@@ -2053,8 +2034,9 @@ CREATE ASSERTION name CHECK ( condition ) ...@@ -2053,8 +2034,9 @@ CREATE ASSERTION name CHECK ( condition )
<term>NOT DEFERRABLE</term> <term>NOT DEFERRABLE</term>
<listitem> <listitem>
<para> <para>
means that the Constraint must be checked for The constraint must be checked at the end of each statement.
violation of its rule after the execution of every SQL statement. SET CONSTRAINTS ALL DEFERRED will have no effect on this type
of constraint.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -2062,8 +2044,10 @@ CREATE ASSERTION name CHECK ( condition ) ...@@ -2062,8 +2044,10 @@ CREATE ASSERTION name CHECK ( condition )
<term>DEFERRABLE</term> <term>DEFERRABLE</term>
<listitem> <listitem>
<para> <para>
means that checking of the Constraint may be deferred This controls whether the constraint can be deferred to the end
until some later time, but no later than the end of the current of the transaction. If SET CONSTRAINTS ALL DEFERRED is used or
the constraint is set to INITIALLY DEFERRED, this will cause
the foreign key to be checked only at the end of the
transaction. transaction.
</para> </para>
</listitem> </listitem>
...@@ -2079,9 +2063,8 @@ CREATE ASSERTION name CHECK ( condition ) ...@@ -2079,9 +2063,8 @@ CREATE ASSERTION name CHECK ( condition )
<term>INITIALLY IMMEDIATE</term> <term>INITIALLY IMMEDIATE</term>
<listitem> <listitem>
<para> <para>
means that, as of the start of the transaction, Check constraint only at the end of the transaction. This
the Constraint must be checked for violation of its rule after the is the default
execution of every SQL statement.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -2089,9 +2072,8 @@ CREATE ASSERTION name CHECK ( condition ) ...@@ -2089,9 +2072,8 @@ CREATE ASSERTION name CHECK ( condition )
<term>INITIALLY DEFERRED</term> <term>INITIALLY DEFERRED</term>
<listitem> <listitem>
<para> <para>
means that, as of the start of the transaction, Check constraint after each statement.
checking of the Constraint may be deferred until some later time, </para>
but no later than the end of the current transaction.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment