@ -1,5 +1,5 @@
<!--
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.66 2003/04/14 18:08:58 tgl Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.67 2003/04/22 10:08:08 petere Exp $
PostgreSQL documentation
PostgreSQL documentation
-->
-->
@ -29,7 +29,7 @@ where <replaceable class="PARAMETER">column_constraint</replaceable> is:
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY |
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY |
CHECK (<replaceable class="PARAMETER">expression</replaceable>) |
CHECK (<replaceable class="PARAMETER">expression</replaceable>) |
REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL ]
REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
[ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] }
[ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
@ -40,7 +40,7 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) |
PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) |
CHECK ( <replaceable class="PARAMETER">expression</replaceable> ) |
CHECK ( <replaceable class="PARAMETER">expression</replaceable> ) |
FOREIGN KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> [, ... ] ) ]
FOREIGN KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> [, ... ] ) ]
[ MATCH FULL | MATCH PARTIAL ] [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] }
[ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
</synopsis>
</synopsis>
@ -58,17 +58,16 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<para>
<para>
If a schema name is given (for example, <literal>CREATE TABLE
If a schema name is given (for example, <literal>CREATE TABLE
myschema.mytable ...</>) then the table is created in the
myschema.mytable ...</>) then the table is created in the
specified schema. Otherwise it is created in the current schema (the one
specified schema. Otherwise it is created in the current schema.
at the front of the search path; see <literal>CURRENT_SCHEMA()</>).
Temporary tables exist in a special schema, so a schema name may not be
TEMP tables exist in a special schema, so a schema name may not be
given when creating a temporary table.
given when creating a TEMP table.
The table name must be distinct from the name of any other table,
The table name must be distinct from the name of any other table,
sequence, index, or view in the same schema.
sequence, index, or view in the same schema.
</para>
</para>
<para>
<para>
<command>CREATE TABLE</command> also automatically creates a data
<command>CREATE TABLE</command> also automatically creates a data
type that represents the tuple type (structure type) corresponding
type that represents the composite type corresponding
to one row of the table. Therefore, tables cannot have the same
to one row of the table. Therefore, tables cannot have the same
name as any existing data type in the same schema.
name as any existing data type in the same schema.
</para>
</para>
@ -81,9 +80,8 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<para>
<para>
The optional constraint clauses specify constraints (or tests) that
The optional constraint clauses specify constraints (or tests) that
new or updated rows must satisfy for an insert or update operation
new or updated rows must satisfy for an insert or update operation
to succeed. A constraint is a named rule: an SQL object which
to succeed. A constraint is an SQL object that helps define the
helps define valid sets of values by putting limits on the results
set of valid values in the table in various ways.
of insert, update, or delete operations performed on a table.
</para>
</para>
<para>
<para>
@ -158,7 +156,7 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<para>
<para>
The <literal>DEFAULT</> clause assigns a default data value for
The <literal>DEFAULT</> clause assigns a default data value for
the column whose column definition it appears within. The value
the column whose column definition it appears within. The value
is any variable-free expression (subselect s and cross-references
is any variable-free expression (subquerie s and cross-references
to other columns in the current table are not allowed). The
to other columns in the current table are not allowed). The
data type of the default expression must match the data type of the
data type of the default expression must match the data type of the
column.
column.
@ -167,7 +165,7 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<para>
<para>
The default expression will be used in any insert operation that
The default expression will be used in any insert operation that
does not specify a value for the column. If there is no default
does not specify a value for the column. If there is no default
for a column, then the default is NULL .
for a column, then the default is null .
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
@ -212,7 +210,8 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><literal>WITH OIDS</> or <literal>WITHOUT OIDS</></term>
<term><literal>WITH OIDS</></term>
<term><literal>WITHOUT OIDS</></term>
<listitem>
<listitem>
<para>
<para>
This optional clause specifies whether rows of the new table
This optional clause specifies whether rows of the new table
@ -250,7 +249,7 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<term><literal>NOT NULL</></term>
<term><literal>NOT NULL</></term>
<listitem>
<listitem>
<para>
<para>
The column is not allowed to contain NULL values.
The column is not allowed to contain null values.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
@ -259,7 +258,7 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<term><literal>NULL</></term>
<term><literal>NULL</></term>
<listitem>
<listitem>
<para>
<para>
The column is allowed to contain NULL values. This is the default.
The column is allowed to contain null values. This is the default.
</para>
</para>
<para>
<para>
@ -276,7 +275,7 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<listitem>
<listitem>
<para>
<para>
The <literal>UNIQUE</literal> constraint specifies a rule that a
The <literal>UNIQUE</literal> constraint specifies that a
group of one or more distinct columns of a table may contain
group of one or more distinct columns of a table may contain
only unique values. The behavior of the unique table constraint
only unique values. The behavior of the unique table constraint
is the same as that for column constraints, with the additional
is the same as that for column constraints, with the additional
@ -284,7 +283,7 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
</para>
</para>
<para>
<para>
For the purpose of a unique constraint, NULL values are not
For the purpose of a unique constraint, null values are not
considered equal.
considered equal.
</para>
</para>
@ -303,11 +302,11 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<listitem>
<listitem>
<para>
<para>
The primary key constraint specifies that a column or columns of a table
The primary key constraint specifies that a column or columns of a table
may contain only unique (non-duplicate), non-NULL values.
may contain only unique (non-duplicate), nonnull values.
Technically, <literal>PRIMARY KEY</literal> is merely a
Technically, <literal>PRIMARY KEY</literal> is merely a
combination of <literal>UNIQUE</> and <literal>NOT NULL</>, but
combination of <literal>UNIQUE</> and <literal>NOT NULL</>, but
identifying a set of columns as primary key also provides
identifying a set of columns as primary key also provides
meta- data about the design of the schema, as a primary key
metadata about the design of the schema, as a primary key
implies that other tables
implies that other tables
may rely on this set of columns as a unique identifier for rows.
may rely on this set of columns as a unique identifier for rows.
</para>
</para>
@ -329,21 +328,19 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<term><literal>CHECK (<replaceable class="PARAMETER">expression</replaceable>)</literal></term>
<term><literal>CHECK (<replaceable class="PARAMETER">expression</replaceable>)</literal></term>
<listitem>
<listitem>
<para>
<para>
<literal>CHECK</> clauses specify integrity constraints or tests
The <literal>CHECK</> clause specifies an expression producing a
which new or updated rows must satisfy for an insert or update
Boolean result which new or updated rows must satisfy for an
operation to succeed. Each constraint must be an expression
insert or update operation to succeed. A check constraint
producing a Boolean result. A condition appearing within a
specified as a column constraint should reference that column's
column definition should reference that column's value only,
value only, while an expression appearing in a table constraint
while a condition appearing as a table constraint may reference
may reference multiple columns.
multiple columns.
</para>
</para>
<para>
<para>
Currently, <literal>CHECK</literal> expressions cannot contain
Currently, <literal>CHECK</literal> expressions cannot contain
subselect s nor refer to variables other than columns of the
subquerie s nor refer to variables other than columns of the
current row.
current row.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
@ -360,7 +357,7 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<listitem>
<listitem>
<para>
<para>
The <literal>REFERENCES</literal> column constraint specifies
Theses clauses specify a foreign key constraint, which specifies
that a group of one or more columns of the new table must only
that a group of one or more columns of the new table must only
contain values which match against values in the referenced
contain values which match against values in the referenced
column(s) <replaceable class="parameter">refcolumn</replaceable>
column(s) <replaceable class="parameter">refcolumn</replaceable>
@ -374,23 +371,23 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
</para>
</para>
<para>
<para>
A value added to these columns is matched against the values of
A value inserted into these columns is matched against the
the referenced table and referenced columns using the given
values of the referenced table and referenced columns using the
match type. There are three match types: <literal>MATCH
given match type. There are three match types: <literal>MATCH
FULL</>, <literal>MATCH PARTIAL</>, and a default match type if
FULL</>, <literal>MATCH PARTIAL</>, and <literal>MATCH
none is specified. <literal>MATCH FULL</> will not allow one
SIMPLE</literal>, which is also the default. <literal>MATCH
column of a multicolumn foreign key to be NULL unless all
FULL</> will not allow one column of a multicolumn foreign key
foreign key columns are NULL. The default match type allows some
to be null unless all foreign key columns are null.
foreign key columns to be NULL while other parts of the foreign
<literal>MATCH SIMPLE</literal> allows some foreign key columns
key are not NULL. <literal>MATCH PARTIAL</> is not ye t
to be null while other parts of the foreign key are no t
implemented.
null. <literal>MATCH PARTIAL</> is not yet implemented.
</para>
</para>
<para>
<para>
In addition, when the data in the referenced columns is changed,
In addition, when the data in the referenced columns is changed,
certain actions are performed on the data in this table's
certain actions are performed on the data in this table's
columns. The <literal>ON DELETE</literal> clause specifies the
columns. The <literal>ON DELETE</literal> clause specifies the
action to do when a referenced row in the referenced table is
action to perform when a referenced row in the referenced table is
being deleted. Likewise, the <literal>ON UPDATE</literal>
being deleted. Likewise, the <literal>ON UPDATE</literal>
clause specifies the action to perform when a referenced column
clause specifies the action to perform when a referenced column
in the referenced table is being updated to a new value. If the
in the referenced table is being updated to a new value. If the
@ -434,7 +431,7 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<term><literal>SET NULL</literal></term>
<term><literal>SET NULL</literal></term>
<listitem>
<listitem>
<para>
<para>
Set the referencing column values to NULL .
Set the referencing column values to null .
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
@ -449,19 +446,20 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
</varlistentry>
</varlistentry>
</variablelist>
</variablelist>
</para>
</para>
<para>
<para>
If primary key column is updated frequently, it may be wise to
If primary key column is updated frequently, it may be wise to
add an index to the <literal>REFERENCES</literal> column so that
add an index to the foreign key column so that <literal>NO
<literal>NO ACTION</literal> and <literal>CASCADE</literal>
ACTION</literal> and <literal>CASCADE</literal> actions
actions associated with the <literal>REFERENCES</literal>
associated with the foreign key column can be more efficiently
column can be more efficiently performed.
performed.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><literal>DEFERRABLE</literal> or <literal>NOT DEFERRABLE</literal></term>
<term><literal>DEFERRABLE</literal></term>
<term><literal>NOT DEFERRABLE</literal></term>
<listitem>
<listitem>
<para>
<para>
This controls whether the constraint can be deferred. A
This controls whether the constraint can be deferred. A
@ -477,7 +475,8 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><literal>INITIALLY IMMEDIATE</literal> or <literal>INITIALLY DEFERRED</literal></term>
<term><literal>INITIALLY IMMEDIATE</literal></term>
<term><literal>INITIALLY DEFERRED</literal></term>
<listitem>
<listitem>
<para>
<para>
If a constraint is deferrable, this clause specifies the default
If a constraint is deferrable, this clause specifies the default
@ -541,45 +540,16 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<refsect1 id="SQL-CREATETABLE-diagnostics">
<refsect1 id="SQL-CREATETABLE-diagnostics">
<title>Diagnostics</title>
<title>Diagnostics</title>
<msgset>
<variablelist>
<msgentry>
<varlistentry>
<msg>
<term><computeroutput>CREATE TABLE</computeroutput></term>
<msgmain>
<listitem>
<msgtext>
<para>
<simpara><computeroutput>CREATE TABLE</computeroutput></simpara>
Message returned if the table was successfully created.
</msgtext>
</para>
</msgmain>
</listitem>
</msg>
</varlistentry>
</variablelist>
<msgexplan>
<para>
Message returned if table is successfully created.
</para>
</msgexplan>
</msgentry>
<msgentry>
<msg>
<msgmain>
<msgtext>
<simpara><computeroutput>ERROR</computeroutput></simpara>
</msgtext>
</msgmain>
</msg>
<msgexplan>
<para>
Message returned if table creation failed. This is usually
accompanied by some descriptive text, such as:
<computeroutput>ERROR: Relation '<replaceable
class="parameter">table</replaceable>' already
exists</computeroutput>, which occurs at run time if the table
specified already exists in the database.
</para>
</msgexplan>
</msgentry>
</msgset>
</refsect1>
</refsect1>
@ -622,17 +592,6 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
</para>
</para>
</listitem>
</listitem>
<listitem>
<para>
The SQL92 standard says that <literal>CHECK</> column constraints
may only refer to the column they apply to; only
<literal>CHECK</> table constraints may refer to multiple
columns. <productname>PostgreSQL</productname> does not enforce
this restriction; it treats column and table check constraints
alike.
</para>
</listitem>
<listitem>
<listitem>
<para>
<para>
Unique constraints and primary keys are not inherited in the
Unique constraints and primary keys are not inherited in the
@ -653,19 +612,19 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<programlisting>
<programlisting>
CREATE TABLE films (
CREATE TABLE films (
code CHARACTER (5) CONSTRAINT firstkey PRIMARY KEY,
code char (5) CONSTRAINT firstkey PRIMARY KEY,
title CHARACTER VARYING (40) NOT NULL,
title varchar (40) NOT NULL,
did DECIMAL(3) NOT NULL,
did integer NOT NULL,
date_prod DATE ,
date_prod date ,
kind CHAR (10),
kind varchar (10),
len INTERVAL HOUR TO MINUTE
len interval hour to minute
);
);
</programlisting>
</programlisting>
<programlisting>
<programlisting>
CREATE TABLE distributors (
CREATE TABLE distributors (
did DECIMAL(3) PRIMARY KEY DEFAULT NEXTVAL ('serial'),
did integer PRIMARY KEY DEFAULT nextval ('serial'),
name VARCHAR (40) NOT NULL CHECK (name <> '')
name varchar (40) NOT NULL CHECK (name <> '')
);
);
</programlisting>
</programlisting>
</para>
</para>
@ -675,23 +634,24 @@ CREATE TABLE distributors (
<programlisting>
<programlisting>
CREATE TABLE array (
CREATE TABLE array (
vector INT [][]
vector int [][]
);
);
</programlisting>
</programlisting>
</para>
</para>
<para>
<para>
Define a unique table constraint for the table films. Unique table
Define a unique table constraint for the table
constraints can be defined on one or more columns of the table:
<literal>films</literal>. Unique table constraints can be defined
on one or more columns of the table.
<programlisting>
<programlisting>
CREATE TABLE films (
CREATE TABLE films (
code CHAR (5),
code char (5),
title VARCHAR (40),
title varchar (40),
did DECIMAL(3) ,
did integer ,
date_prod DATE ,
date_prod date ,
kind VARCHAR (10),
kind varchar (10),
len INTERVAL HOUR TO MINUTE ,
len interval hour to minute ,
CONSTRAINT production UNIQUE(date_prod)
CONSTRAINT production UNIQUE(date_prod)
);
);
</programlisting>
</programlisting>
@ -702,8 +662,8 @@ CREATE TABLE films (
<programlisting>
<programlisting>
CREATE TABLE distributors (
CREATE TABLE distributors (
did DECIMAL(3) CHECK (did > 100),
did integer CHECK (did > 100),
name VARCHAR (40)
name varchar (40)
);
);
</programlisting>
</programlisting>
</para>
</para>
@ -713,8 +673,8 @@ CREATE TABLE distributors (
<programlisting>
<programlisting>
CREATE TABLE distributors (
CREATE TABLE distributors (
did DECIMAL(3) ,
did integer ,
name VARCHAR (40)
name varchar (40)
CONSTRAINT con1 CHECK (did > 100 AND name <> '')
CONSTRAINT con1 CHECK (did > 100 AND name <> '')
);
);
</programlisting>
</programlisting>
@ -727,12 +687,12 @@ CREATE TABLE distributors (
<programlisting>
<programlisting>
CREATE TABLE films (
CREATE TABLE films (
code CHAR (5),
code char (5),
title VARCHAR (40),
title varchar (40),
did DECIMAL(3) ,
did integer ,
date_prod DATE ,
date_prod date ,
kind VARCHAR (10),
kind varchar (10),
len INTERVAL HOUR TO MINUTE ,
len interval hour to minute ,
CONSTRAINT code_title PRIMARY KEY(code,title)
CONSTRAINT code_title PRIMARY KEY(code,title)
);
);
</programlisting>
</programlisting>
@ -746,33 +706,33 @@ CREATE TABLE films (
<programlisting>
<programlisting>
CREATE TABLE distributors (
CREATE TABLE distributors (
did DECIMAL(3) ,
did integer ,
name CHAR VARYING (40),
name varchar (40),
PRIMARY KEY(did)
PRIMARY KEY(did)
);
);
</programlisting>
</programlisting>
<programlisting>
<programlisting>
CREATE TABLE distributors (
CREATE TABLE distributors (
did DECIMAL(3) PRIMARY KEY,
did integer PRIMARY KEY,
name VARCHAR (40)
name varchar (40)
);
);
</programlisting>
</programlisting>
</para>
</para>
<para>
<para>
This assigns a literal constant default value for the column
This assigns a literal constant default value for the column
<literal>name</literal>, and a rranges for the default value of
<literal>name</literal>, arranges for the default value of column
column <literal>did</literal> to be generated by selecting the next
<literal>did</literal> to be generated by selecting the next value
value of a sequence object. T he default value of
of a sequence object, and makes t he default value of
<literal>modtime</literal> will be the time at which the row is
<literal>modtime</literal> be the time at which the row is
inserted.
inserted.
<programlisting>
<programlisting>
CREATE TABLE distributors (
CREATE TABLE distributors (
name VARCHAR(40) DEFAULT 'luso f ilms',
name varchar(40) DEFAULT 'Luso F ilms',
did INTEGER DEFAULT NEXTVAL ('distributors_serial'),
did integer DEFAULT nextval ('distributors_serial'),
modtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
modtime timestamp DEFAULT current_timestamp
);
);
</programlisting>
</programlisting>
</para>
</para>
@ -784,8 +744,8 @@ CREATE TABLE distributors (
<programlisting>
<programlisting>
CREATE TABLE distributors (
CREATE TABLE distributors (
did DECIMAL(3) CONSTRAINT no_null NOT NULL,
did integer CONSTRAINT no_null NOT NULL,
name VARCHAR (40) NOT NULL
name varchar (40) NOT NULL
);
);
</programlisting>
</programlisting>
</para>
</para>
@ -795,8 +755,8 @@ CREATE TABLE distributors (
<programlisting>
<programlisting>
CREATE TABLE distributors (
CREATE TABLE distributors (
did DECIMAL(3) ,
did integer ,
name VARCHAR (40) UNIQUE
name varchar (40) UNIQUE
);
);
</programlisting>
</programlisting>
@ -804,8 +764,8 @@ CREATE TABLE distributors (
<programlisting>
<programlisting>
CREATE TABLE distributors (
CREATE TABLE distributors (
did DECIMAL(3) ,
did integer ,
name VARCHAR (40),
name varchar (40),
UNIQUE(name)
UNIQUE(name)
);
);
</programlisting>
</programlisting>
@ -818,8 +778,7 @@ CREATE TABLE distributors (
<para>
<para>
The <command>CREATE TABLE</command> command conforms to SQL92
The <command>CREATE TABLE</command> command conforms to SQL92
and to a subset of SQL99, with exceptions listed below and in the
and to a subset of SQL99, with exceptions listed below.
descriptions above.
</para>
</para>
<refsect2>
<refsect2>
@ -827,27 +786,25 @@ CREATE TABLE distributors (
<para>
<para>
Although the syntax of <literal>CREATE TEMPORARY TABLE</literal>
Although the syntax of <literal>CREATE TEMPORARY TABLE</literal>
resembles that of SQL92 , the effect is not the same. In the standard,
resembles that of SQL standard , the effect is not the same. In the standard,
temporary tables are defined just once and automatically exist (starting
temporary tables are defined just once and automatically exist (starting
with empty contents) in every session that needs them.
with empty contents) in every session that needs them.
<productname>PostgreSQL</productname> instead
<productname>PostgreSQL</productname> instead
requires each session to issue its own <literal>CREATE TEMPORARY
requires each session to issue its own <literal>CREATE TEMPORARY
TABLE</literal> command for each temporary table to be used. This allows
TABLE</literal> command for each temporary table to be used. This allows
different sessions to use the same temporary table name for different
different sessions to use the same temporary table name for different
purposes, whereas the spec 's approach constrains all instances of a
purposes, whereas the standard 's approach constrains all instances of a
given temporary table name to have the same table structure.
given temporary table name to have the same table structure.
</para>
</para>
<note>
<para>
<para>
The spec-mandated behavior of temporary tables is widely ignored.
The behavior of temporary tables mandated by the standard is
<productname>PostgreSQL</productname>'s behavior on this point is simila r
widely ignored. <productname>PostgreSQL</productname>'s behavior
to that of several other RDBM Ss.
on this point is similar to that of several other SQL database s.
</para>
</para>
</note>
<para>
<para>
SQL92 's distinction between global and local temporary tables
The standard 's distinction between global and local temporary tables
is not in <productname>PostgreSQL</productname>, since that distinction
is not in <productname>PostgreSQL</productname>, since that distinction
depends on the concept of modules, which
depends on the concept of modules, which
<productname>PostgreSQL</productname> does not have.
<productname>PostgreSQL</productname> does not have.
@ -855,64 +812,40 @@ CREATE TABLE distributors (
<para>
<para>
The <literal>ON COMMIT</literal> clause for temporary tables
The <literal>ON COMMIT</literal> clause for temporary tables
also resembles SQL92 , but has some differences.
also resembles the SQL standard , but has some differences.
If the <literal>ON COMMIT</> clause is omitted, SQL92 specifies that the
If the <literal>ON COMMIT</> clause is omitted, SQL specifies that the
default behavior is <literal>ON COMMIT DELETE ROWS</>. However, the
default behavior is <literal>ON COMMIT DELETE ROWS</>. However, the
default behavior in <productname>PostgreSQL</productname> is
default behavior in <productname>PostgreSQL</productname> is
<literal>ON COMMIT PRESERVE ROWS</literal>. The <literal>ON COMMIT
<literal>ON COMMIT PRESERVE ROWS</literal>. The <literal>ON COMMIT
DROP</literal> option does not exist in SQL92 .
DROP</literal> option does not exist in SQL.
</para>
</para>
</refsect2>
</refsect2>
<refsect2>
<refsect2>
<title><literal>NULL</literal> <quote>Constraint</quote> </title>
<title>Column Check Constraints </title>
<para>
<para>
The <literal>NULL</> <quote>constraint</quote> (actually a
The SQL standard says that <literal>CHECK</> column constraints
non-constraint) is a <productname>PostgreSQL</productname>
may only refer to the column they apply to; only <literal>CHECK</>
extension to SQL92 that is included for compatibility with some
table constraints may refer to multiple columns.
other RDBMSs (and for symmetry with the <literal>NOT
<productname>PostgreSQL</productname> does not enforce this
NULL</literal> constraint). Since it is the default for any
restriction; it treats column and table check constraints alike.
column, its presence is simply noise.
</para>
</para>
</refsect2>
</refsect2>
<refsect2>
<refsect2>
<title>Assertions</title>
<title><literal>NULL</literal> <quote>Constraint</quote></title>
<para>
An assertion is a special type of integrity constraint and shares
the same namespace as other constraints. However, an assertion is
not necessarily dependent on one particular table as constraints
are, so SQL92 provides the <command>CREATE ASSERTION</command>
statement as an alternate method for defining a constraint:
<synopsis>
CREATE ASSERTION <replaceable>name</replaceable> CHECK ( <replaceable>condition</replaceable> )
</synopsis>
</para>
<para>
<para>
<productname>PostgreSQL</> does not implement assertions at present.
The <literal>NULL</> <quote>constraint</quote> (actually a
non-constraint) is a <productname>PostgreSQL</productname>
extension to the SQL standard that is included for compatibility with some
other database systems (and for symmetry with the <literal>NOT
NULL</literal> constraint). Since it is the default for any
column, its presence is simply noise.
</para>
</para>
</refsect2>
</refsect2>
<!--
<para>
Domain constraints are defined by <command>CREATE
DOMAIN</command> or <command>ALTER DOMAIN</command> statements:
</para>
<para>
Domain constraint:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] CHECK <replaceable>constraint</replaceable>
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
[ [ NOT ] DEFERRABLE ]
</synopsis>
</para>
-->
<refsect2>
<refsect2>
<title>Inheritance</title>
<title>Inheritance</title>