+ class="PARAMETER">column_constraint_clause to
+ refer to that column only,
Postgres
+ allows multiple columns to be referenced within a single column
+ constraint. See the column constraint clause for more
+ information.
table_constraint_clause
- The optional table CONSTRAINT clause specifies a list of integrity
- constraints which new or updated entries must satisfy for
- an insert or update operation to succeed. Each constraint
- must evaluate to a boolean expression. Multiple columns
- may be referenced within a single constraint.
- Only one PRIMARY KEY clause may be specified for a table;
- PRIMARY KEY column
- (a table constraint) and PRIMARY KEY (a column constraint) are
- mutually exclusive..
- See the table constraint clause for more information.
+ The optional table CONSTRAINT clause specifies a
+ list of integrity constraints which new or updated entries must
+ satisfy for an insert or update operation to succeed. Each
+ constraint must evaluate to a boolean expression. Multiple
+ columns may be referenced within a single constraint. Only one
+ PRIMARY KEY clause may be specified for a table;
+ PRIMARY KEY column (a table
+ constraint) and PRIMARY KEY (a column constraint)
+ are mutually exclusive.. See the table constraint clause for
+ more information.
Postgres automatically allows the created
table to inherit functions on tables above it in the inheritance
hierarchy.
-
-
Aside
- Inheritance of functions is done according
- to the conventions of the Common Lisp Object System (CLOS).
-
-
- 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
release.
SESSION_USER
- not yet supported
+ See CURRENT_USER function
SYSTEM_USER
- not yet supported
+ See CURRENT_USER function
This column is a primary key, which implies that uniqueness is
- enforced by the system and that other tables may rely on this column
- as a unique identifier for rows.
- See PRIMARY KEY for more information.
+ enforced by the system and that other tables may rely on this
+ column as a unique identifier for rows. See PRIMARY KEY for more
+ information.
- The optional constraint
- clauses specify constraints or tests which new or updated entries
- must satisfy for an insert or update operation to succeed. Each constraint
- must evaluate to a boolean expression. Multiple attributes may be referenced within
- a single constraint. The use of PRIMARY KEY
- as a table constraint
- is mutually incompatible with PRIMARY KEY as a column constraint.
+ The optional constraint clauses specify constraints or tests which
+ new or updated entries must satisfy for an insert or update
+ operation to succeed. Each constraint must evaluate to a boolean
+ expression. Multiple attributes may be referenced within a single
+ constraint. The use of PRIMARY KEY as a table constraint is mutually
+ incompatible with PRIMARY KEY as a column constraint.
- A column constraint is an integrity constraint defined as part
- of a column definition, and logically becomes a table
- constraint as soon as it is created. The column
- constraints available are:
+ A column constraint is an integrity constraint defined as part of a
+ column definition, and logically becomes a table constraint as soon
+ as it is created. The column constraints available are:
PRIMARY KEY
NOT NULL
-
-
- (new for v7.0) supports
- REFERENCES integrity constraints.
-
-
The column definitions of the specified columns do not have to
include a NOT NULL constraint to be included in a UNIQUE
- constraint. Having more than one null value in a column without a
- NOT NULL constraint, does not violate a UNIQUE constraint.
- (This deviates from the
SQL92 definition, but
- is a more sensible convention. See the section on compatibility
- for more details.).
+ constraint. Having more than one null value in a column without a
+ NOT NULL constraint, does not violate a UNIQUE constraint. (This
+ deviates from the
SQL92 definition, but is a
+ more sensible convention. See the section on compatibility for more
+ details.).
Each UNIQUE column constraint must name a column that is
Description
The CHECK constraint specifies a restriction on allowed values
- within a column.
- The CHECK constraint is also allowed as a table constraint.
+ within a column. The CHECK constraint is also allowed as a table
+ constraint.
The SQL92 CHECK column constraints can only be defined on, and
- refer to, one column of the table.
Postgres
- does not have
- this restriction.
+ refer to, one column of the table.
+
Postgres does not have this restriction.
Description
- The PRIMARY KEY column constraint specifies that a column of a table
- may contain only unique
- (non-duplicate), non-NULL values. The definition of
- the specified column does not have to include an explicit NOT NULL
- constraint to be included in a PRIMARY KEY constraint.
+ The PRIMARY KEY column constraint specifies that a column of a
+ table may contain only unique (non-duplicate), non-NULL values. The
+ definition of the specified column does not have to include an
+ explicit NOT NULL constraint to be included in a PRIMARY KEY
+ constraint.
Only one PRIMARY KEY can be specified for a table.
MATCH matchtype
- 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.
+ 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.
+ MATCH PARTIAL is not
+ currently supported.
deleted. There are the following actions.
- CASCADE
+ NO ACTION
- Delete any rows referencing the deleted row.
+ Produce error if foreign key violated. This is the default.
RESTRICT
- Disallow deletion of rows being referenced.
+ Same as NO ACTION.
- SET NULL
+ CASCADE
- Set the referencing column values to NULL.
+ Delete any rows referencing the deleted row.
- SET DEFAULT
+ SET NULL
- Set the referencing column values to their default value.
+ Set the referencing column values to NULL.
- NO ACTION
+ SET DEFAULT
- Do nothing.
+ Set the referencing column values to their default value.
ON UPDATE action
- 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.
+ 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.
- CASCADE
+ NO ACTION
- Update the value of the referencing column to the new value of the
- referenced column.
+ Produce error if foreign key violated. This is the default.
RESTRICT
- Disallow update of row being referenced.
+ Same as NO ACTION.
- SET NULL
+ CASCADE
- Set the referencing column values to NULL.
+ Update the value of the referencing column to the new value of the
+ referenced column.
- SET DEFAULT
+ SET NULL
- Set the referencing column values to their default value.
+ Set the referencing column values to NULL.
- NO ACTION
+ SET DEFAULT
- Do nothing.
+ Set the referencing column values to their default value.
[ NOT ] DEFERRABLE
- Tells the trigger manager whether this constraint may be
- deferred to the end of transaction.
+ This controls whether the constraint can be deferred to the end
+ 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.
checktime has two possible values
which specify the default time to check the constraint.
-
DEFERRED
- Check this constraint at the end of the transaction.
+ Check constraint only at the end of the transaction.
-
IMMEDIATE
- Check this constraint after each statement.
+ Check constraint after each statement. This is the default.
Description
- 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.
+ 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.
- 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.
+ 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.
Notes
- Currently
Postgres 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
Postgres does not
- enforce this.
+ Currently
Postgres 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
Postgres
+ does not enforce this.
FOREIGN KEY
-
-
- supports FOREIGN KEY
- integrity constraints
-
-
- The UNIQUE constraint specifies a rule that a group of one or
- more distinct columns of a table may contain only unique values.
- The behavior of the UNIQUE table constraint is the same as that for column
- constraints, with the additional capability to span multiple columns.
+ The UNIQUE constraint specifies a rule that a group of one or more
+ distinct columns of a table may contain only unique values. The
+ behavior of the UNIQUE table constraint is the same as that for
+ column constraints, with the additional capability to span multiple
+ columns.
See the section on the UNIQUE column constraint for more details.
ERROR: Cannot insert a duplicate key into a unique index.
- This occurs at run-time if one tries to insert a duplicate value into
- a column subject to a PRIMARY KEY constraint.
+ This occurs at run-time if one tries to insert a duplicate
+ value into a column subject to a PRIMARY KEY constraint.
[ MATCH matchtype ]
[ ON DELETE action ]
[ ON UPDATE action ]
-[ [ NOT ] DEFERRABLE ]
+[ [ NOT ] DEFERRABLE ]
[ INITIALLY checktime ]
- 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.
+ 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.
MATCH matchtype
- 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.
+ 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.
+ MATCH PARTIAL is not currently supported.
deleted. There are the following actions.
- CASCADE
+ NO ACTION
- Delete any rows referencing the deleted row.
+ Produce error if foreign key violated. This is the default.
RESTRICT
- Disallow deletion of rows being referenced.
+ Same as NO ACTION.
- SET NULL
+ CASCADE
- Set the referencing column values to NULL.
+ Delete any rows referencing the deleted row.
- SET DEFAULT
+ SET NULL
- Set the referencing column values to their default value.
+ Set the referencing column values to NULL.
- NO ACTION
+ SET DEFAULT
- Do nothing.
+ Set the referencing column values to their default value.
ON UPDATE action
- 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.
+ 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.
- CASCADE
+ NO ACTION
- Update the value of the referencing column to the new value of the
- referenced column.
+ Produce error if foreign key violated. This is the default.
- SET NULL
+ CASCADE
- Set the referencing column values to NULL.
+ Update the value of the referencing column to the new value
+ of the referenced column.
- SET DEFAULT
+ SET NULL
- Set the referencing column values to their default value.
+ Set the referencing column values to NULL.
- NO ACTION
+ SET DEFAULT
- Do nothing.
+ Set the referencing column values to their default value.
[ NOT ] DEFERRABLE
- Tells the trigger manager whether this constraint may be
- deferred to the end of transaction.
+ This controls whether the constraint can be deferred to the end
+ 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.
INITIALLY checktime
- checktime has two possible values
- which specify the default time to check the constraint.
+ checktime has two
+ possible values which specify the default time to check the
+ constraint.
- DEFERRED
+ IMMEDIATE
- Check this constraint at the end of the transaction.
+ Check constraint after each statement. This is the default.
- IMMEDIATE
+ DEFERRED
- Check this constraint after each statement.
+ Check constraint only at the end of the transaction.
- The FOREIGN KEY table constraint is similar to that for column constraints,
- with the additional capability of encompassing multiple columns.
+ The FOREIGN KEY table constraint is similar to that for column
+ constraints, with the additional capability of encompassing
+ multiple columns.
Refer to the section on the FOREIGN KEY column constraint for more
constraints.
- The optional ON COMMIT clause of CREATE TEMPORARY TABLE
- specifies whether or not the temporary table should be emptied of
- rows whenever COMMIT is executed. If the ON COMMIT clause is
- omitted, the default option, ON COMMIT DELETE ROWS, is assumed.
+ The optional ON COMMIT clause of CREATE TEMPORARY TABLE specifies
+ whether or not the temporary table should be emptied of rows
+ whenever COMMIT is executed. If the ON COMMIT clause is omitted, the
+ default option, ON COMMIT DELETE ROWS, is assumed.
To create a temporary table:
NULL clause
- The NULL "constraint" (actually a non-constraint)
- is a
Postgres extension to SQL92
- is included for symmetry with the NOT NULL clause. Since it is the default
- for any column, its presence is simply noise.
+ The NULL "constraint" (actually a non-constraint) is a
+
Postgres extension to SQL92 is
+ included for symmetry with the NOT NULL clause. Since it is the
+ default for any column, its presence is simply noise.
[ CONSTRAINT name ] NULL
An assertion is a special type of integrity constraint and share
- the same namespace as other constraints.
- However, an assertion is not necessarily dependent on one
- particular base table as constraints are, so SQL-92 provides the
- CREATE ASSERTION statement as an alternate method for defining a
- constraint:
+ the same namespace as other constraints. However, an assertion is
+ not necessarily dependent on one particular base table as
+ constraints are, so SQL-92 provides the CREATE ASSERTION statement
+ as an alternate method for defining a constraint:
CREATE ASSERTION name CHECK ( condition )
NOT DEFERRABLE
- means that the Constraint must be checked for
- violation of its rule after the execution of every SQL statement.
+ The constraint must be checked at the end of each statement.
+ SET CONSTRAINTS ALL DEFERRED will have no effect on this type
+ of constraint.
DEFERRABLE
- means that checking of the Constraint may be deferred
- until some later time, but no later than the end of the current
- transaction.
+ This controls whether the constraint can be deferred to the end
+ 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.
INITIALLY IMMEDIATE
- means that, as of the start of the transaction,
- the Constraint must be checked for violation of its rule after the
- execution of every SQL statement.
+ Check constraint only at the end of the transaction. This
+ is the default
INITIALLY DEFERRED
- means that, as of the start of the transaction,
- checking of the Constraint may be deferred until some later time,
- but no later than the end of the current transaction.
+ Check constraint after each statement.
+