Commit f08c9ff8 authored by Peter Eisentraut's avatar Peter Eisentraut

Make the CREATE TABLE ref page more readable and update some information.

parent e97fe98c
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.29 2001/10/12 00:07:14 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.30 2001/10/22 18:14:47 petere Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -161,15 +161,14 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> ...@@ -161,15 +161,14 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
<para> <para>
<command>ALTER TABLE</command> changes the definition of an existing table. <command>ALTER TABLE</command> changes the definition of an existing table.
The <literal>ADD COLUMN</literal> form adds a new column to the table The <literal>ADD COLUMN</literal> form adds a new column to the table
using the same syntax as <xref linkend="SQL-CREATETABLE" using the same syntax as <xref linkend="SQL-CREATETABLE">.
endterm="SQL-CREATETABLE-title">.
The <literal>ALTER COLUMN SET/DROP DEFAULT</literal> forms The <literal>ALTER COLUMN SET/DROP DEFAULT</literal> forms
allow you to set or remove the default for the column. Note that defaults allow you to set or remove the default for the column. Note that defaults
only apply to subsequent <command>INSERT</command> commands; they do not only apply to subsequent <command>INSERT</command> commands; they do not
cause rows already in the table to change. cause rows already in the table to change.
The <literal>ALTER COLUMN SET STATISTICS</literal> form allows you to The <literal>ALTER COLUMN SET STATISTICS</literal> form allows you to
set the statistics-gathering target for subsequent set the statistics-gathering target for subsequent
<xref linkend="sql-analyze" endterm="sql-analyze-title"> operations. <xref linkend="sql-analyze"> operations.
The <literal>RENAME</literal> clause causes the name of a table or column The <literal>RENAME</literal> clause causes the name of a table or column
to change without changing any of the data contained in to change without changing any of the data contained in
the affected table. Thus, the table or column will the affected table. Thus, the table or column will
...@@ -177,7 +176,7 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> ...@@ -177,7 +176,7 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
executed. executed.
The ADD <replaceable class="PARAMETER">table constraint definition</replaceable> clause The ADD <replaceable class="PARAMETER">table constraint definition</replaceable> clause
adds a new constraint to the table using the same syntax as <xref adds a new constraint to the table using the same syntax as <xref
linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title">. linkend="SQL-CREATETABLE">.
The DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> clause The DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> clause
drops all CHECK constraints on the table (and its children) that match <replaceable class="PARAMETER">constraint</replaceable>. drops all CHECK constraints on the table (and its children) that match <replaceable class="PARAMETER">constraint</replaceable>.
The OWNER clause changes the owner of the table to the user <replaceable class="PARAMETER"> The OWNER clause changes the owner of the table to the user <replaceable class="PARAMETER">
...@@ -205,18 +204,17 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> ...@@ -205,18 +204,17 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
You can use the <literal>SET DEFAULT</literal> form You can use the <literal>SET DEFAULT</literal> form
of <command>ALTER TABLE</command> to set the default later. of <command>ALTER TABLE</command> to set the default later.
(You may also want to update the already existing rows to the (You may also want to update the already existing rows to the
new default value, using <xref linkend="sql-update" new default value, using <xref linkend="sql-update">.)
endterm="sql-update-title">.)
</para> </para>
<para> <para>
Currently only CHECK constraints can be dropped from a table. The RESTRICT Currently only CHECK constraints can be dropped from a table. The RESTRICT
keyword is required, although dependencies are not checked. The CASCADE keyword is required, although dependencies are not checked. The CASCADE
option is unsupported. To remove a PRIMARY or UNIQUE constraint, drop the option is unsupported. To remove a PRIMARY or UNIQUE constraint, drop the
relevant index using the <xref linkend="SQL-DROPINDEX" endterm="SQL-DROPINDEX-TITLE"> command. relevant index using the <xref linkend="SQL-DROPINDEX"> command.
To remove FOREIGN KEY constraints you need to recreate To remove FOREIGN KEY constraints you need to recreate
and reload the table, using other parameters to the and reload the table, using other parameters to the
<xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title"> <xref linkend="SQL-CREATETABLE">
command. command.
</para> </para>
<para> <para>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.47 2001/10/09 18:46:00 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.48 2001/10/22 18:14:47 petere Exp $
Postgres documentation Postgres documentation
--> -->
<refentry id="SQL-CREATETABLE"> <refentry id="SQL-CREATETABLE">
<refmeta> <refmeta>
<refentrytitle id="sql-createtable-title"> <refentrytitle>CREATE TABLE</refentrytitle>
CREATE TABLE
</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo> <refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta> </refmeta>
<refnamediv> <refnamediv>
<refname> <refname>CREATE TABLE</refname>
CREATE TABLE <refpurpose>define a new table</refpurpose>
</refname>
<refpurpose>
define a new table
</refpurpose>
</refnamediv> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
<refsynopsisdivinfo> <synopsis>
<date>2001-01-11</date> CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> (
</refsynopsisdivinfo> { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [, ... ] ]
<synopsis> | <replaceable>table_constraint</replaceable> } [, ... ]
CREATE [ TEMPORARY | TEMP ] TABLE <replaceable class="PARAMETER">table_name</replaceable> ( )
{ <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">type</replaceable> [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ] [ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
| <replaceable>table_constraint</replaceable> } [, ... ] ) [ WITH OIDS | WITHOUT OIDS ]
[ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
[ WITH OIDS | WITHOUT OIDS ] where <replaceable class="PARAMETER">column_constraint</replaceable> is:
where <replaceable class="PARAMETER">column_constraint</replaceable> can be:
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ] [ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY | DEFAULT <replaceable class="PARAMETER">value</replaceable> | CHECK (<replaceable class="PARAMETER">condition</replaceable>) | { NOT NULL | NULL | UNIQUE | PRIMARY KEY |
REFERENCES <replaceable class="PARAMETER">table</replaceable> [ ( <replaceable class="PARAMETER">column</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL ] CHECK (<replaceable class="PARAMETER">expression</replaceable>) |
[ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL ]
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] }
} [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
and <replaceable class="PARAMETER">table_constraint</replaceable> is:
and <replaceable class="PARAMETER">table_constraint</replaceable> can be:
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ] [ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
{ UNIQUE ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) | { UNIQUE ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) |
PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) | PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) |
CHECK ( <replaceable class="PARAMETER">condition</replaceable> ) | CHECK ( <replaceable class="PARAMETER">expression</replaceable> ) |
FOREIGN KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] ) REFERENCES <replaceable class="PARAMETER">table</replaceable> [ ( <replaceable class="PARAMETER">column</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 ] [ 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>
<refsect2 id="R2-SQL-CREATETABLE-1">
<title>
Inputs
</title>
<para>
<variablelist>
<varlistentry>
<term>TEMPORARY or TEMP</term>
<listitem>
<para>
If specified, the table is created only for this session, and is
automatically dropped on session exit.
Existing permanent tables with the same name are not visible
(in this session) while the temporary table exists.
Any indexes created on a temporary table are automatically
temporary as well.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">table_name</replaceable></term>
<listitem>
<para>
The name of the new table to be created.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">column_name</replaceable></term>
<listitem>
<para>
The name of a column to be created in the new table.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">type</replaceable></term>
<listitem>
<para>
The type of the column. This may include array specifiers.
Refer to the <citetitle>PostgreSQL User's Guide</citetitle> for
further information about data types and arrays.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">parent_table</replaceable></term>
<listitem>
<para>
The optional INHERITS clause specifies a list of table
names from which this table automatically inherits all fields.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>WITH OIDS or WITHOUT OIDS</term>
<listitem>
<para>
This optional clause specifies whether rows of the new table should
have OIDs (object identifiers) assigned to them. The default is
WITH OIDS. (If the new table inherits from any tables that have OIDs,
then WITH OIDS is forced even if the command says WITHOUT OIDS.)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">constraint_name</replaceable></term>
<listitem>
<para>
An optional name for a column or table constraint. If not specified,
the system generates a name.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">value</replaceable></term>
<listitem>
<para>
A default value for a column.
See the DEFAULT clause for more information.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">condition</replaceable></term>
<listitem>
<para>
CHECK clauses specify integrity constraints or tests which new or
updated rows must satisfy for an insert or update operation to
succeed. Each constraint must be an expression producing
a boolean result.
A condition appearing within a column definition should reference
that column's value only, while a condition appearing as a table
constraint may reference multiple columns.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">table</replaceable></term>
<listitem>
<para>
The name of an existing table to be referenced by a foreign
key constraint.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">column</replaceable></term>
<listitem>
<para>
The name of a column in an existing table to be referenced by a
foreign key constraint. If not specified, the primary key of
the existing table is assumed.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">action</replaceable></term>
<listitem>
<para>
A keyword indicating the action to take when a foreign key
constraint is violated.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
<refsect2 id="R2-SQL-CREATETABLE-2">
<title>
Outputs
</title>
<para>
<variablelist>
<varlistentry>
<term><computeroutput>
CREATE
</computeroutput></term>
<listitem>
<para>
Message returned if table is successfully created.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
ERROR
</computeroutput></term>
<listitem>
<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 runtime if the table specified already exists
in the database.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
</refsynopsisdiv> </refsynopsisdiv>
<refsect1 id="R1-SQL-CREATETABLE-1"> <refsect1 id="SQL-CREATETABLE-description">
<title> <title>Description</title>
Description
</title>
<para> <para>
<command>CREATE TABLE</command> will enter a new, initially empty table <command>CREATE TABLE</command> will create a new, initially empty table
into the current database. The table will be owned by the user issuing the in the current database. The table will be owned by the user issuing the
command. command.
</para> </para>
<para> <para>
Each <replaceable class="PARAMETER">type</replaceable> <command>CREATE TABLE</command> also automatically creates a data
may be a simple type, a complex type (set) or an array type. type that represents the tuple type (structure type) corresponding
Each attribute may be specified to be non-null and to one row of the table. Therefore, tables cannot have the same
each may have a default value, specified by the name as any existing data type.
<xref linkend="R1-SQL-DEFAULTCLAUSE-1" endterm="R1-SQL-DEFAULTCLAUSE-1-TITLE">.
</para> </para>
<para> <para>
<note> A table cannot have more than 1600 columns. (In practice, the
<para> effective limit is lower because of tuple-length constraints). A
Consistent array dimensions within an table cannot have the same name as a system catalog table.
attribute are not enforced. This will likely change in a future
release.
</para>
</note>
</para> </para>
<para> <para>
<command>CREATE TABLE</command> also automatically creates a data type The optional constraint clauses specify constraints (or tests) that
that represents the tuple type (structure type) corresponding to one new or updated rows must satisfy for an insert or update operation
row of the table. Therefore, tables can't have the same name as any to succeed. A constraint is a named rule: an SQL object which
existing datatype. helps define valid sets of values by putting limits on the results
of insert, update, or delete operations performed on a table.
</para> </para>
<para> <para>
A table can have no more than 1600 columns (in practice, the There are two ways to define constraints: table constraints and
effective limit is lower because of tuple-length constraints). column constraints. A column constraint is defined as part of a
A table cannot have the same name as a system catalog table. column definition. A table constraint definition is not tied to a
particular column, and it can encompass more than one column.
Every column constraint can also be written as a table constraint;
a column constraint is only a notational convenience if the
constraint only affects one column.
</para> </para>
</refsect1> </refsect1>
<refsect1 id="R1-SQL-INHERITSCLAUSE-1"> <refsect1>
<title id="R1-SQL-INHERITSCLAUSE-1-TITLE"> <title>Parameters</title>
INHERITS Clause
</title>
<para>
<synopsis>
INHERITS ( <replaceable class="PARAMETER">parent_table</replaceable> [, ... ] )
</synopsis>
</para>
<para> <variablelist>
The optional INHERITS
clause specifies a list of table names from which the new table
automatically inherits all fields. If the same field name appears in
more than one parent table, Postgres reports an error unless the field
definitions match in each of the parent tables. If there is no
definition conflict, then the duplicate fields are merged to form a single
field of the new table. If the new table's own field list contains a
field name that is also inherited, this declaration must likewise match
the inherited field(s), and the field definitions are merged into one.
</para>
<para>
Inherited and new field declarations of the same name must specify exactly
the same data type to avoid an error. They need not specify identical
constraints --- all constraints provided from any declaration are merged
together and all are applied to the new table. If the new table explicitly
specifies a default value for the field, this default overrides any
defaults from inherited declarations of the field. Otherwise, any parents
that specify default values for the field must all specify the same
default, or an error will be reported.
</para>
<para> <varlistentry>
Postgres automatically allows the created table to inherit functions on <term><literal>[LOCAL] TEMPORARY</> or <literal>[LOCAL] TEMP</></term>
tables above it in the inheritance hierarchy; that is, if we create table <listitem>
<literal>foo</literal> inheriting from <literal>bar</literal>, then <para>
functions that accept the tuple type <literal>bar</literal> can also be If specified, the table is created as a temporary table.
applied to instances of <literal>foo</literal>. (Currently, this works Temporary tables are automatically dropped at the end of a
reliably for functions on the first or only parent table, but not so well session. Existing persistent tables with the same name are not
for functions on additional parents.) visible to the current session while the temporary table exists.
</para> Any indexes created on a temporary table are automatically
</refsect1> temporary as well.
</para>
<refsect1 id="R1-SQL-OIDSCLAUSE-1">
<title id="R1-SQL-OIDSCLAUSE-1-TITLE">
OIDS Clause
</title>
<para>
<synopsis>
WITH OIDS | WITHOUT OIDS
</synopsis>
</para>
<para>
This clause controls whether an OID (object ID) is generated and assigned
to each row inserted into the table. The default is WITH OIDS.
Specifying WITHOUT OIDS allows the user to suppress generation of
OIDs for rows of a table. This may be worthwhile for large
tables, since it will reduce OID consumption and thereby postpone
wraparound of the 32-bit OID counter. Once the counter wraps around,
uniqueness of OIDs can no longer be assumed, which considerably reduces
their usefulness.
</para>
<para>
Whenever an application makes use of OIDs to identify specific rows of
a table, it is recommended that you create a unique index on OID for
that table, to ensure that OIDs in the table will indeed uniquely
identify rows even after counter wraparound. (An index on OID is needed
anyway for fast lookup of rows by OID.) Avoid assuming that OIDs are
unique across tables --- if you need a database-wide unique identifier,
use the combination of tableoid and row OID for the purpose. (It is
likely that future Postgres releases will use a separate OID counter
for each table, so that it will be <emphasis>necessary</> not optional
to include tableoid to have a unique identifier database-wide.)
</para>
<tip>
<para>
WITHOUT OIDS is not recommended for tables with no primary key, since
without either an OID or a unique data key, it is difficult to identify
specific rows.
</para>
</tip>
</refsect1>
<refsect1 id="R1-SQL-DEFAULTCLAUSE-1">
<title id="R1-SQL-DEFAULTCLAUSE-1-TITLE">
DEFAULT Clause
</title>
<para>
<synopsis>
DEFAULT <replaceable class="PARAMETER">value</replaceable>
</synopsis>
</para>
<para> <para>
The DEFAULT clause assigns a default data value for the column whose The <literal>LOCAL</literal> word is optional. But see under
column definition it appears within. The value is any variable-free <xref linkend="sql-createtable-compatibility"
expression (note that sub-selects and cross-references to other endterm="sql-createtable-compatibility-title">.
columns in the current table are not supported). </para>
The data type of a default value must match the column definition's </listitem>
data type. </varlistentry>
</para>
<para> <varlistentry>
The DEFAULT expression will be used in any INSERT operation that does <term><replaceable class="PARAMETER">table_name</replaceable></term>
not specify a value for the column. If there is no DEFAULT clause, <listitem>
then the default is NULL. <para>
</para> The name of the table to be created.
</para>
</listitem>
</varlistentry>
<refsect2 id="R2-SQL-DEFAULTCLAUSE-2"> <varlistentry>
<title> <term><replaceable class="PARAMETER">column_name</replaceable></term>
Usage <listitem>
</title> <para>
The name of a column to be created in the new table.
</para>
</listitem>
</varlistentry>
<para> <varlistentry>
<programlisting> <term><replaceable class="PARAMETER">data_type</replaceable></term>
CREATE TABLE distributors ( <listitem>
name VARCHAR(40) DEFAULT 'luso films', <para>
did INTEGER DEFAULT NEXTVAL('distributors_serial'), The data type of the column. This may include array specifiers.
modtime TIMESTAMP DEFAULT now() Refer to the <citetitle>User's Guide</citetitle> for further
); information about data types and arrays.
</programlisting> </para>
The above assigns a literal constant default value for the column </listitem>
<literal>name</literal>, and arranges for the default value of column </varlistentry>
<literal>did</literal> to be generated by selecting the next value of a
sequence object. The default value of <literal>modtime</literal> will
be the time at which the row is inserted.
</para>
<para> <varlistentry>
It is worth remarking that <term><literal>DEFAULT
<programlisting> <replaceable>default_expr</replaceable></literal></term>
modtime TIMESTAMP DEFAULT 'now' <listitem>
</programlisting> <para>
would produce a result that is probably not the intended one: the The <literal>DEFAULT</> clause assigns a default data value for
string <literal>'now'</literal> will be coerced to a timestamp value the column whose column definition it appears within. The value
immediately, and so the default value of <literal>modtime</literal> will is any variable-free expression (subselects and cross-references
always be the time of table creation. This difficulty is avoided by to other columns in the current table are not allowed). The
specifying the default value as a function call. data type of the default expression must match the data type of the
</para> column.
</refsect2> </para>
</refsect1>
<refsect1 id="R1-SQL-COLUMNCONSTRAINT-1"> <para>
<title id="R1-SQL-COLUMNCONSTRAINT-1-TITLE"> The default expression will be used in any insert operation that
Column Constraints does not specify a value for the column. If there is no default
</title> for a column, then the default is NULL.
<para> </para>
<synopsis> </listitem>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] { </varlistentry>
NULL | NOT NULL | UNIQUE | PRIMARY KEY | CHECK <replaceable
class="parameter">condition</replaceable> |
REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</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">checktime</replaceable> ] }
</synopsis>
</para>
<refsect2 id="R2-SQL-COLUMNCONSTRAINT-1"> <varlistentry>
<title> <term><literal>INHERITS ( <replaceable>parent_table</replaceable> [, ... ] )</literal></term>
Inputs <listitem>
</title> <para>
<para> The optional <literal>INHERITS</> clause specifies a list of
tables from which the new table automatically inherits all
columns. If the same column name exists in more than one parent
table, an error is reported unless the data types of the columns
match in each of the parent tables. If there is no conflict,
then the duplicate columns are merged to form a single column in
the new table. If the column name list of the new table
contains a column that is also inherited, the data type must
likewise match the inherited column(s), and the column
definitions are merged into one. However, inherited and new
column declarations of the same name need not specify identical
constraints: all constraints provided from any declaration are
merged together and all are applied to the new table. If the
new table explicitly specifies a default value for the column,
this default overrides any defaults from inherited declarations
of the column. Otherwise, any parents that specify default
values for the column must all specify the same default, or an
error will be reported.
</para>
<!--
<para>
Postgres automatically allows the created table to inherit
functions on tables above it in the inheritance hierarchy; that
is, if we create table <literal>foo</literal> inheriting from
<literal>bar</literal>, then functions that accept the tuple
type <literal>bar</literal> can also be applied to instances of
<literal>foo</literal>. (Currently, this works reliably for
functions on the first or only parent table, but not so well for
functions on additional parents.)
</para>
-->
</listitem>
</varlistentry>
<variablelist> <varlistentry>
<varlistentry> <term><literal>WITH OIDS</> or <literal>WITHOUT OIDS</></term>
<term><replaceable class="parameter">constraint_name</replaceable></term> <listitem>
<listitem> <para>
<para> This optional clause specifies whether rows of the new table
An arbitrary name given to a constraint clause. should have OIDs (object identifiers) assigned to them. The
</para> default is to have OIDs. (If the new table inherits from any
</listitem> tables that have OIDs, then <literal>WITH OIDS</> is forced even
</varlistentry> if the command says <literal>WITHOUT OIDS</>.)
</para>
<varlistentry>
<term>NULL</term>
<listitem>
<para>
The column is allowed to contain NULL values. This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>NOT NULL</term>
<listitem>
<para>
The column is not allowed to contain NULL values.
This is equivalent to the column constraint
CHECK (<replaceable class="PARAMETER">column</replaceable> NOT NULL).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>UNIQUE</term>
<listitem>
<para>
The column must have unique values. In <productname>Postgres</productname>
this is enforced by automatic creation of a unique index on the column.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>PRIMARY KEY</term>
<listitem>
<para>
This column is a primary key, which implies that other tables may rely
on this column as a unique identifier for rows. Both UNIQUE and
NOT NULL are implied by PRIMARY KEY. See PRIMARY KEY for more
information.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<replaceable class="parameter">condition</replaceable>
</term>
<listitem>
<para>
An arbitrary boolean-valued constraint condition.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
<refsect2 id="R2-SQL-COLUMNCONSTRAINT-2"> <para>
<title> Specifying <literal>WITHOUT OIDS</> allows the user to suppress
Description generation of OIDs for rows of a table. This may be worthwhile
</title> for large tables, since it will reduce OID consumption and
thereby postpone wraparound of the 32-bit OID counter. Once the
counter wraps around, uniqueness of OIDs can no longer be
assumed, which considerably reduces their usefulness.
</para>
</listitem>
</varlistentry>
<para> <varlistentry>
The optional constraint clauses specify constraints or tests which <term><literal>CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable></literal></term>
new or updated rows must satisfy for an insert or update <listitem>
operation to succeed. <para>
</para> An optional name for a column or table constraint. If not specified,
the system generates a name.
</para>
</listitem>
</varlistentry>
<para> <varlistentry>
A constraint is a named rule: an SQL object which helps define <term><literal>NOT NULL</></term>
valid sets of values by putting limits on the results of INSERT, <listitem>
UPDATE or DELETE operations performed on a table. <para>
</para> The column is not allowed to contain NULL values. This is
equivalent to the column constraint <literal>CHECK (<replaceable
class="PARAMETER">column</replaceable> NOT NULL)</literal>.
</para>
</listitem>
</varlistentry>
<para> <varlistentry>
There are two ways to define integrity constraints: <term><literal>NULL</></term>
table constraints, covered later, and column constraints, covered here. <listitem>
</para> <para>
The column is allowed to contain NULL values. This is the default.
</para>
<para> <para>
A column constraint is an integrity constraint defined as part of a This clause is only available for compatibility with
column definition, and logically becomes a table constraint as soon non-standard SQL databases. Its use is discouraged in new
as it is created. The column constraints available are: applications.
</para>
<simplelist columns="1"> </listitem>
<member>PRIMARY KEY</member> </varlistentry>
<member>REFERENCES</member>
<member>UNIQUE</member>
<member>CHECK</member>
<member>NOT NULL</member>
</simplelist>
</para>
</refsect2>
<refsect2 id="R2-SQL-NOTNULL-1"> <varlistentry>
<title> <term><literal>UNIQUE</> (column constraint)</term>
NOT NULL Constraint <term><literal>UNIQUE ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] )</> (table constraint)</term>
</title>
<synopsis>
[ CONSTRAINT <replaceable class="parameter">name</replaceable> ] NOT NULL
</synopsis>
<para>
The NOT NULL constraint specifies a rule that a column may
contain only non-null values.
This is a column constraint only, and not allowed
as a table constraint.
</para>
<refsect3 id="R3-SQL-NOTNULL-1">
<title>
Outputs
</title>
<para>
<variablelist>
<varlistentry>
<term><replaceable>status</replaceable></term>
<listitem>
<para>
<variablelist>
<varlistentry>
<term><computeroutput>
ERROR: ExecAppend: Fail to add null value in not null attribute "<replaceable class="parameter">column</replaceable>".
</computeroutput></term>
<listitem>
<para>
This error occurs at runtime if one tries to insert a null value
into a column which has a NOT NULL constraint.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3 id="R3-SQL-NOTNULL-2">
<title>
Description
</title>
<para>
</para>
</refsect3>
<refsect3 id="R3-SQL-NOTNULL-3">
<title>
Usage
</title>
<para>
Define two NOT NULL column constraints on the table
<classname>distributors</classname>,
one of which is explicitly given a name:
<programlisting> <listitem>
CREATE TABLE distributors ( <para>
did DECIMAL(3) CONSTRAINT no_null NOT NULL, The <literal>UNIQUE</literal> constraint specifies a rule that a
name VARCHAR(40) NOT NULL group of one or more distinct columns of a table may contain
); only unique values. The behavior of the unique table constraint
</programlisting> is the same as that for column constraints, with the additional
</para> capability to span multiple columns.
</refsect3> </para>
</refsect2>
<refsect2 id="R2-SQL-UNIQUECLAUSE-1"> <para>
<title> For the purpose of a unique constraint, NULL values are not
UNIQUE Constraint considered equal.
</title> </para>
<synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] UNIQUE
</synopsis>
<refsect3> <para>
<title>Inputs</title> Each unique table constraint must name a set of columns that is
<para> different from the set of columns named by any other unique or
primary key constraint defined for the table. (Otherwise it
would just be the same constraint listed twice.)
</para>
</listitem>
</varlistentry>
<variablelist> <varlistentry>
<varlistentry> <term><literal>PRIMARY KEY</> (column constraint)</term>
<term><replaceable class="parameter">constraint_name</replaceable></term> <term><literal>PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] )</> (table constraint)</term>
<listitem> <listitem>
<para> <para>
An arbitrary name given to a constraint clause. The primary key constraint specifies that a column or columns of a table
</para> may contain only unique (non-duplicate), non-NULL values.
</listitem> Technically, <literal>PRIMARY KEY</literal> is merely a
</varlistentry> combination of <literal>UNIQUE</> and <literal>NOT NULL</>, but
</variablelist> identifying a set of columns as primary key also provides
</para> meta-data about the design of the schema, as a primary key
</refsect3> implies that other tables
may rely on this set of columns as a unique identifier for rows.
<refsect3> </para>
<title>Outputs</title>
<para>
<variablelist>
<varlistentry>
<term><replaceable>status</replaceable></term>
<listitem>
<para>
<variablelist>
<varlistentry>
<term><computeroutput>
ERROR: Cannot insert a duplicate key into a unique index.
</computeroutput></term>
<listitem>
<para>
This error occurs at runtime if one tries to insert a
duplicate value into a column.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3> <para>
<title> Only one primary key can be specified for a table, whether as a
Description column constraint or a table constraint.
</title> </para>
<para>
The UNIQUE constraint specifies a rule that a group of one or
more distinct columns of a table may contain only unique values.
</para>
<para>
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 <acronym>SQL92</acronym> definition, but is a
more sensible convention. See the section on compatibility for more
details.)
</para>
<para>
Each UNIQUE column constraint must name a column that is
different from the set of columns named by any other UNIQUE or
PRIMARY KEY constraint defined for the table.
</para>
<note>
<para> <para>
<productname>Postgres</productname> automatically creates a unique The primary key constraint should name a set of columns that is
index for each UNIQUE constraint, to assure different from other sets of columns named by any unique
data integrity. See CREATE INDEX for more information. constraint defined for the same table.
</para> </para>
</note> </listitem>
</refsect3> </varlistentry>
<refsect3 id="R3-SQL-UNIQUECLAUSE-3"> <varlistentry>
<title> <term><literal>CHECK (<replaceable class="PARAMETER">expression</replaceable>)</literal></term>
Usage <listitem>
</title> <para>
<literal>CHECK</> clauses specify integrity constraints or tests
which new or updated rows must satisfy for an insert or update
operation to succeed. Each constraint must be an expression
producing a Boolean result. A condition appearing within a
column definition should reference that column's value only,
while a condition appearing as a table constraint may reference
multiple columns.
</para>
<para> <para>
Defines a UNIQUE constraint for the <literal>name</literal> column: Currently, <literal>CHECK</literal> expressions cannot contain
<programlisting> subselects nor refer to variables other than columns of the
CREATE TABLE distributors ( current row.
did DECIMAL(3), </para>
name VARCHAR(40) UNIQUE
);
</programlisting>
which is equivalent to the following specified as a table constraint: </listitem>
<programlisting> </varlistentry>
CREATE TABLE distributors (
did DECIMAL(3),
name VARCHAR(40),
UNIQUE(name)
);
</programlisting>
</para>
</refsect3>
</refsect2>
<refsect2 id="R2-SQL-CHECK-1">
<title>
The CHECK Constraint
</title>
<synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] CHECK ( <replaceable>condition</replaceable> )
</synopsis>
<refsect3 id="R3-SQL-CHECK-1">
<title>Inputs</title>
<para>
<variablelist> <varlistentry>
<varlistentry> <term><literal>REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> ) ] [ MATCH <replaceable class="parameter">matchtype</replaceable> ] [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ]</literal> (column constraint)</term>
<term><replaceable class="parameter">constraint_name</replaceable></term>
<listitem>
<para>
An arbitrary name given to a constraint clause.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>condition</replaceable></term>
<listitem>
<para>
Any valid conditional expression evaluating to a boolean result.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3 id="R3-SQL-CHECK-2"> <term><literal>FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ... ] )
<title> REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ... ] ) ]
Outputs [ MATCH <replaceable class="parameter">matchtype</replaceable> ]
</title> [ ON DELETE <replaceable class="parameter">action</replaceable> ]
<para> [ ON UPDATE <replaceable class="parameter">action</replaceable> ]</literal>
(table constraint)</term>
<variablelist> <listitem>
<varlistentry> <para>
<term><replaceable>status</replaceable></term> The <literal>REFERENCES</literal> column constraint specifies
<listitem> that a group of one or more columns of the new table must only
<para> contain values which match against values in the referenced
column(s) <replaceable class="parameter">refcolumn</replaceable>
<variablelist> of the referenced table <replaceable
<varlistentry> class="parameter">reftable</replaceable>. If <replaceable
<term><computeroutput> class="parameter">refcolumn</replaceable> is omitted, the
ERROR: ExecAppend: rejected due to CHECK constraint "<replaceable class="parameter">constraint_name</replaceable>". primary key of the <replaceable
</computeroutput></term> class="parameter">reftable</replaceable> is used. The
<listitem> referenced columns must be the columns of a unique or primary
<para> key constraint in the referenced table.
This error occurs at runtime if one tries to insert an illegal </para>
value into a column subject to a CHECK constraint.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3> <para>
<title>Description</title> A value added to these columns is matched against the values of
<para> the referenced table and referenced columns using the given
The CHECK constraint specifies a generic restriction on allowed values match type. There are three match types: <literal>MATCH
within a column. The CHECK constraint is also allowed as a table FULL</>, <literal>MATCH PARTIAL</>, and a default match type if
constraint. none is specified. <literal>MATCH FULL</> will not allow one
</para> column of a multi-column foreign key to be NULL unless all
<para> foreign key columns are NULL. The default match type allows some
CHECK specifies a general boolean expression involving one or more foreign key columns to be NULL while other parts of the foreign
columns of a table. A new row will be rejected if the boolean key are not NULL. <literal>MATCH PARTIAL</> is not yet
expression evaluates to FALSE when applied to the row's values. implemented.
</para> </para>
<para>
Currently, CHECK expressions cannot contain sub-selects nor refer
to variables other than fields of the current row.
</para>
<para>
The SQL92 standard says that CHECK column constraints may only refer
to the column they apply to; only CHECK table constraints may refer
to multiple columns.
<productname>Postgres</productname> does not enforce this restriction.
It treats column and table CHECK constraints alike.
</para>
</refsect3>
</refsect2>
<refsect2 id="R2-SQL-PRIMARYKEY-1">
<title>
PRIMARY KEY Constraint
</title>
<synopsis>
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ] PRIMARY KEY
</synopsis>
<refsect3>
<title>Inputs</title>
<para>
<variablelist>
<varlistentry>
<term><replaceable class="PARAMETER">constraint_name</replaceable></term>
<listitem>
<para>
An arbitrary name given to a constraint clause.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3>
<title>Outputs</title>
<variablelist>
<varlistentry>
<term><computeroutput>
ERROR: Cannot insert a duplicate key into a unique index.
</computeroutput></term>
<listitem>
<para>
This occurs at runtime if one tries to insert a duplicate value into
a column subject to a PRIMARY KEY constraint.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect3>
<refsect3>
<title>Description</title>
<para>
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.
</para>
<para>
Only one PRIMARY KEY can be specified for a table, whether as a
column constraint or a table constraint.
</para>
</refsect3>
<refsect3 id="R3-SQL-PRIMARYKEY-3"> <para>
<title> In addition, when the data in the referenced columns is changed,
Notes certain actions are performed on the data in this table's
</title> columns. The <literal>ON DELETE</literal> clause specifies the
<para> action to do when a referenced row in the referenced table is
<productname>Postgres</productname> automatically creates being deleted. Likewise, the <literal>ON UPDATE</literal>
a unique index to assure clause specifies the action to perform when a referenced column
data integrity (see CREATE INDEX statement). in the referenced table is being updated to a new value. If the
</para> row is updated, but the referenced column is not actually
<para> changed, no action is done. There are the following possible
The PRIMARY KEY constraint should name a set of columns that is actions for each clause:
different from other sets of columns named by any UNIQUE constraint
defined for the same table, since it will result in duplication <variablelist>
of equivalent indexes and unproductive additional runtime overhead. <varlistentry>
However, <productname>Postgres</productname> does not specifically <term><literal>NO ACTION</literal></term>
disallow this. <listitem>
</para> <para>
</refsect3> Produce an error indicating that the deletion or update
</refsect2> would create a foreign key constraint violation. This is
the default action.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>RESTRICT</literal></term>
<listitem>
<para>
Same as <literal>NO ACTION</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
Delete any rows referencing the deleted row, or update the
value of the referencing column to the new value of the
referenced column, respectively.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>SET NULL</literal></term>
<listitem>
<para>
Set the referencing column values to NULL.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>SET DEFAULT</literal></term>
<listitem>
<para>
Set the referencing column values to their default value.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<refsect2 id="R2-SQL-REFERENCES-1"> </listitem>
<refsect2info> </varlistentry>
<date>2000-02-04</date>
</refsect2info> <varlistentry>
<title> <term><literal>DEFERRABLE</literal> or <literal>NOT DEFERRABLE</literal></term>
REFERENCES Constraint <listitem>
</title> <para>
<synopsis> This controls whether the constraint can be deferred. A
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> ) ] constraint that is not deferrable will be checked immediately
[ MATCH <replaceable class="parameter">matchtype</replaceable> ] after every command. Checking of constraints that are
[ ON DELETE <replaceable class="parameter">action</replaceable> ] deferrable may be postponed until the end of the transaction
[ ON UPDATE <replaceable class="parameter">action</replaceable> ] (using the <xref linkend="sql-set-constraints"> command).
[ [ NOT ] DEFERRABLE ] <literal>NOT DEFERRABLE</literal> is the default. Only foreign
[ INITIALLY <replaceable class="parameter">checktime</replaceable> ] key constraints currently accept this clause. All other
</synopsis> constraint types are not deferrable.
<para> </para>
The REFERENCES constraint specifies a rule that a column </listitem>
value is checked against the values of another column. </varlistentry>
REFERENCES can also be specified as part of
a FOREIGN KEY table constraint.
</para>
<refsect3 id="R3-SQL-REFERENCES-1"> <varlistentry>
<title>Inputs</title> <term><literal>INITIALLY IMMEDIATE</literal> or <literal>INITIALLY DEFERRED</literal></term>
<listitem>
<para>
If a constraint is deferrable, this clause specifies the default
time to check the constraint. If the constraint is
<literal>INITIALLY IMMEDIATE</literal>, it is checked after each
statement. This is the default. If the constraint is
<literal>INITIALLY DEFERRED</literal>, it is checked only at the
end of the transaction. The constraint check time can be
altered with the <xref linkend="sql-set-constraints"> command.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id="SQL-CREATETABLE-diagnostics">
<title>Diagnostics</title>
<msgset>
<msgentry>
<msg>
<msgmain>
<msgtext>
<simpara><computeroutput>CREATE</computeroutput></simpara>
</msgtext>
</msgmain>
</msg>
<msgexplan>
<para>
Message returned if table is successfully created.
</para>
</msgexplan>
</msgentry>
<para>
<variablelist>
<varlistentry>
<term><replaceable class="PARAMETER">constraint_name</replaceable></term>
<listitem>
<para>
An arbitrary name given to a constraint clause.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">reftable</replaceable></term>
<listitem>
<para>
The table that contains the data to check against.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">refcolumn</replaceable></term>
<listitem>
<para>
The column in <replaceable class="parameter">reftable</replaceable>
to check the data against. If this is not specified, the PRIMARY KEY of the
<replaceable class="parameter">reftable</replaceable> is used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>MATCH <replaceable class="parameter">matchtype</replaceable></term>
<listitem>
<para>
There are three match types: MATCH FULL, MATCH PARTIAL, and a
default match type if none is specified. MATCH FULL will not
allow one column of a multi-column foreign key to be NULL
unless all foreign key columns are NULL. The default MATCH type
allows some foreign key columns to be NULL while other parts
of the foreign key are not NULL. MATCH PARTIAL is currently not
supported.
</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>NO ACTION</term>
<listitem>
<para>
Produce error if foreign key violated. This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>RESTRICT</term>
<listitem>
<para>
Same as NO ACTION.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>CASCADE</term>
<listitem>
<para>
Delete any rows referencing the deleted row.
</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>
</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>NO ACTION</term>
<listitem>
<para>
Produce error if foreign key violated. This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>RESTRICT</term>
<listitem>
<para>
Same as NO ACTION.
</para>
</listitem>
</varlistentry>
<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>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>
</variablelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term> [ NOT ] DEFERRABLE </term>
<listitem>
<para>
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.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>INITIALLY <replaceable class="parameter">checktime</replaceable></term>
<listitem>
<para>
<replaceable class="parameter">checktime</replaceable> has two possible values
which specify the default time to check the constraint.
<variablelist>
<varlistentry>
<term>DEFERRED</term>
<listitem>
<para>
Check constraint only at the end of the transaction.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>IMMEDIATE</term>
<listitem>
<para>
Check constraint after each statement. This is the default.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3 id="R3-SQL-REFERENCES-2"> <msgentry>
<refsect3info> <msg>
<date>2000-02-04</date> <msgmain>
</refsect3info> <msgtext>
<title> <simpara><computeroutput>ERROR</computeroutput></simpara>
Outputs </msgtext>
</title> </msgmain>
<para> </msg>
<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">reftable</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"> <msgexplan>
<title>Description</title> <para>
<para> Message returned if table creation failed. This is usually
The REFERENCES column constraint specifies that a accompanied by some descriptive text, such as:
column of a table must only contain values which match against <computeroutput>ERROR: Relation '<replaceable
values in a referenced column of a referenced table. class="parameter">table</replaceable>' already
</para> exists</computeroutput>, which occurs at runtime if the table
<para> specified already exists in the database.
A value added to this column is matched against the values of the </para>
referenced table and referenced column using the given match type. </msgexplan>
In addition, when the referenced column data is changed, actions </msgentry>
are run upon this column's matching data. </msgset>
</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 a default 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>
</refsect2>
</refsect1> </refsect1>
<refsect1 id="R1-SQL-TABLECONSTRAINT-1">
<title>
Table Constraints
</title>
<para>
<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">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</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">checktime</replaceable> ]
</synopsis>
</para>
<refsect2 id="R2-SQL-TABLECONSTRAINT-1">
<title>
Inputs
</title>
<para>
<variablelist> <refsect1 id="SQL-CREATETABLE-notes">
<varlistentry> <title>Notes</title>
<term><replaceable class="parameter">constraint_name</replaceable></term>
<listitem>
<para>
An arbitrary name given to a constraint clause.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">column</replaceable> [, ... ]</term>
<listitem>
<para>
The column name(s) for which to define a unique index
and, for PRIMARY KEY, a NOT NULL constraint.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>CHECK ( <replaceable class="parameter">constraint</replaceable> )</term>
<listitem>
<para>
A boolean expression to be evaluated as the constraint.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
<refsect2 id="R2-SQL-TABLECONSTRAINT-2">
<title>
Outputs
</title>
<para>
The possible outputs for the table constraint clause are the same
as for the corresponding portions of the column constraint clause.
</para>
</refsect2>
<refsect2 id="R2-SQL-TABLECONSTRAINT-3">
<title>
Description
</title>
<para>
A table constraint is an integrity constraint defined on one or
more columns of a table. The four variations of <quote>Table
Constraint</quote> are:
<simplelist columns="1">
<member>UNIQUE</member>
<member>CHECK</member>
<member>PRIMARY KEY</member>
<member>FOREIGN KEY</member>
</simplelist>
</para>
</refsect2>
<refsect2 id="R2-SQL-UNIQUECLAUSE-4">
<title>
UNIQUE Constraint
</title>
<para>
<synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] UNIQUE ( <replaceable class="parameter">column</replaceable> [, ... ] )
</synopsis>
</para>
<refsect3>
<title>Inputs</title>
<variablelist>
<varlistentry>
<term><replaceable class="parameter">constraint_name</replaceable></term>
<listitem>
<para>
An arbitrary name given to a constraint clause.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">column</replaceable></term>
<listitem>
<para>
A name of a column in a table.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect3>
<refsect3>
<title>Outputs</title>
<para>
<variablelist>
<varlistentry>
<term><replaceable>status</replaceable></term>
<listitem>
<para>
<variablelist>
<varlistentry>
<term>ERROR: Cannot insert a duplicate key into a unique index</term>
<listitem>
<para>
This error occurs at runtime if one tries to insert a
duplicate value into a column.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3>
<title>
Description
</title>
<para>
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.
</para>
<para>
See the section on the UNIQUE column constraint for more details.
</para>
</refsect3>
<refsect3 id="R3-SQL-UNIQUECLAUSE-4"> <itemizedlist>
<title> <listitem>
Usage
</title>
<para> <para>
Prevent duplicate rows in the table distributors: Whenever an application makes use of OIDs to identify specific
<programlisting> rows of a table, it is recommended to create a unique constraint
CREATE TABLE distributors ( on the <structfield>oid</> column of that table, to ensure that
did DECIMAL(3), OIDs in the table will indeed uniquely identify rows even after
name VARCHAR(40), counter wraparound. Avoid assuming that OIDs are unique across
UNIQUE(did,name) tables; if you need a database-wide unique identifier, use the
); combination of <structfield>tableoid</> and row OID for the
</programlisting> purpose. (It is likely that future <productname>PostgreSQL</>
releases will use a separate OID counter for each table, so that
it will be <emphasis>necessary</>, not optional, to include
<structfield>tableoid</> to have a unique identifier
database-wide.)
</para> </para>
</refsect3>
</refsect2>
<refsect2 id="R2-SQL-PRIMARYKEY-4"> <tip>
<title> <para>
PRIMARY KEY Constraint The use of <literal>WITHOUT OIDS</literal> is not recommended
</title> for tables with no primary key, since without either an OID or a
<para> unique data key, it is difficult to identify specific rows.
<synopsis> </para>
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ] PRIMARY KEY ( <replaceable class="PARAMETER">column</replaceable> [, ... ] ) </tip>
</synopsis> </listitem>
</para>
<refsect3>
<title>Inputs</title>
<para>
<variablelist> <listitem>
<varlistentry>
<term><replaceable class="PARAMETER">constraint_name</replaceable></term>
<listitem>
<para>
An arbitrary name given to a constraint clause.
</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>
</variablelist>
</para>
</refsect3>
<refsect3>
<title>Outputs</title>
<variablelist>
<varlistentry>
<term><replaceable>status</replaceable></term>
<listitem>
<para>
<variablelist>
<varlistentry>
<term>ERROR: Cannot insert a duplicate key into a unique index.</term>
<listitem>
<para>
This occurs at run-time if one tries to insert a duplicate
value into a column subject to a PRIMARY KEY constraint.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect3>
<refsect3>
<title>Description</title>
<para> <para>
The PRIMARY KEY constraint specifies a rule that a group of one <productname>PostgreSQL</productname> automatically creates an
or more distinct columns of a table may contain only unique index for each unique constraint and primary key constraint to
(nonduplicate), non-null values. The column definitions of enforce the uniqueness. Thus, it is not necessary to create an
the specified columns do not have to include a NOT NULL explicit index for primary key columns. (See <xref
constraint to be included in a PRIMARY KEY constraint. linkend="sql-createindex"> for more information.)
</para> </para>
</listitem>
<listitem>
<para> <para>
The PRIMARY KEY table constraint is similar to that for column constraints, The SQL92 standard says that <literal>CHECK</> column constraints
with the additional capability of encompassing multiple columns. 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> </para>
<para> </listitem>
Refer to the section on the PRIMARY KEY column constraint for more
information.
</para>
</refsect3>
</refsect2>
<refsect2 id="R2-SQL-REFERENCES-2"> <listitem>
<refsect2info>
<date>2000-02-04</date>
</refsect2info>
<title>
REFERENCES Constraint
</title>
<synopsis>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ] FOREIGN KEY ( <replaceable class="parameter">column</replaceable> [, ... ] )
REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</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">checktime</replaceable> ]
</synopsis>
<para>
The REFERENCES constraint specifies a rule that a column value or set
of column values is
checked against the values in another table.
</para>
<refsect3 id="R3-SQL-REFERENCES-5">
<title>Inputs</title>
<para> <para>
<variablelist> Unique constraints and primary keys are not inherited in the
<varlistentry> current implementation. This makes the combination of
<term><replaceable class="PARAMETER">constraint_name</replaceable></term> inheritance and unique constraints rather disfunctional.
<listitem>
<para>
An arbitrary name given to a constraint clause.
</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">reftable</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 columns in the <replaceable class="parameter">reftable</replaceable>
to check the data against. If this is not specified, the PRIMARY KEY of the
<replaceable class="parameter">reftable</replaceable> is used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>MATCH <replaceable class="parameter">matchtype</replaceable></term>
<listitem>
<para>
There are three match types: MATCH FULL, MATCH PARTIAL, and a
default match type if none is specified. MATCH FULL will not
allow one column of a multi-column foreign key to be NULL
unless all foreign key columns are NULL. The default MATCH type
allows some foreign key columns to be NULL while other parts
of the foreign key are not NULL. MATCH PARTIAL is currently not
supported.
</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>NO ACTION</term>
<listitem>
<para>
Produce error if foreign key violated. This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>RESTRICT</term>
<listitem>
<para>
Same as NO ACTION.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>CASCADE</term>
<listitem>
<para>
Delete any rows referencing the deleted row.
</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>
</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>NO ACTION</term>
<listitem>
<para>
Produce error if foreign key violated. This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>RESTRICT</term>
<listitem>
<para>
Disallow update of row being referenced.
</para>
</listitem>
</varlistentry>
<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>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>
</variablelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term> [ NOT ] DEFERRABLE </term>
<listitem>
<para>
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.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>INITIALLY <replaceable class="parameter">checktime</replaceable></term>
<listitem>
<para>
<replaceable class="parameter">checktime</replaceable> has two
possible values which specify the default time to check the
constraint.
<variablelist>
<varlistentry>
<term>IMMEDIATE</term>
<listitem>
<para>
Check constraint after each statement. This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>DEFERRED</term>
<listitem>
<para>
Check constraint only at the end of the transaction.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3 id="R3-SQL-REFERENCES-6">
<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">reftable</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 is related to a group
of distinct columns in the referenced table.
</para> </para>
</listitem>
</itemizedlist>
</refsect1>
<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> <refsect1 id="SQL-CREATETABLE-examples">
<title>Examples</title>
<refsect1 id="R1-SQL-CREATETABLE-2">
<title>
Usage
</title>
<para> <para>
Create table films and table distributors: Create table <structname>films</> and table
<structname>distributors</>:
<programlisting> <programlisting>
CREATE TABLE films ( CREATE TABLE films (
code CHARACTER(5) CONSTRAINT firstkey PRIMARY KEY, code CHARACTER(5) CONSTRAINT firstkey PRIMARY KEY,
title CHARACTER VARYING(40) NOT NULL, title CHARACTER VARYING(40) NOT NULL,
did DECIMAL(3) NOT NULL, did DECIMAL(3) NOT NULL,
date_prod DATE, date_prod DATE,
kind CHAR(10), kind CHAR(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 DECIMAL(3) PRIMARY KEY DEFAULT NEXTVAL('serial'),
name VARCHAR(40) NOT NULL CHECK (name &lt;&gt; '') name VARCHAR(40) NOT NULL CHECK (name &lt;&gt; '')
); );
</programlisting> </programlisting>
</para> </para>
<para> <para>
Create a table with a 2-dimensional array: Create a table with a 2-dimensional array:
<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. Define a unique table constraint for the table films. Unique table
UNIQUE table constraints can be defined on one or more constraints can be defined on one or more columns of the table:
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 DECIMAL(3),
date_prod DATE, date_prod DATE,
kind CHAR(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>
</para> </para>
<para> <para>
Define a CHECK column constraint: Define a check column constraint:
<programlisting> <programlisting>
CREATE TABLE distributors ( CREATE TABLE distributors (
did DECIMAL(3) CHECK (did > 100), did DECIMAL(3) CHECK (did > 100),
name VARCHAR(40) name VARCHAR(40)
); );
</programlisting> </programlisting>
</para> </para>
<para> <para>
Define a CHECK table constraint: Define a check table constraint:
<programlisting> <programlisting>
CREATE TABLE distributors ( CREATE TABLE distributors (
did DECIMAL(3), did DECIMAL(3),
name VARCHAR(40) name VARCHAR(40)
CONSTRAINT con1 CHECK (did > 100 AND name > '') CONSTRAINT con1 CHECK (did > 100 AND name &lt;&gt; '')
); );
</programlisting> </programlisting>
</para> </para>
<para> <para>
Define a PRIMARY KEY table constraint for the table films. Define a primary key table constraint for the table
PRIMARY KEY table constraints can be defined on one or more <structname>films</>. Primary key table constraints can be defined
columns of the table: 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 DECIMAL(3),
date_prod DATE, date_prod DATE,
kind CHAR(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>
</para> </para>
<para> <para>
Defines a PRIMARY KEY column constraint for table distributors. Define a primary key constraint for table
PRIMARY KEY column constraints can only be defined on one column <structname>distributors</>. The following two examples are
of the table (the following two examples are equivalent): equivalent, the first using the table constraint syntax, the second
the column constraint notation.
<programlisting> <programlisting>
CREATE TABLE distributors ( CREATE TABLE distributors (
did DECIMAL(3), did DECIMAL(3),
name CHAR VARYING(40), name CHAR VARYING(40),
PRIMARY KEY(did) PRIMARY KEY(did)
); );
</programlisting> </programlisting>
<programlisting> <programlisting>
CREATE TABLE distributors ( CREATE TABLE distributors (
did DECIMAL(3) PRIMARY KEY, did DECIMAL(3) PRIMARY KEY,
name VARCHAR(40) name VARCHAR(40)
); );
</programlisting> </programlisting>
</para> </para>
<para>
This assigns a literal constant default value for the column
<literal>name</literal>, and arranges for the default value of
column <literal>did</literal> to be generated by selecting the next
value of a sequence object. The default value of
<literal>modtime</literal> will be the time at which the row is
inserted.
<programlisting>
CREATE TABLE distributors (
name VARCHAR(40) DEFAULT 'luso films',
did INTEGER DEFAULT NEXTVAL('distributors_serial'),
modtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
</programlisting>
</para>
<para>
Define two <literal>NOT NULL</> column constraints on the table
<classname>distributors</classname>, one of which is explicitly
given a name:
<programlisting>
CREATE TABLE distributors (
did DECIMAL(3) CONSTRAINT no_null NOT NULL,
name VARCHAR(40) NOT NULL
);
</programlisting>
</para>
<para>
Define a unique constraint for the <literal>name</literal> column:
<programlisting>
CREATE TABLE distributors (
did DECIMAL(3),
name VARCHAR(40) UNIQUE
);
</programlisting>
The above is equivalent to the following specified as a table constraint:
<programlisting>
CREATE TABLE distributors (
did DECIMAL(3),
name VARCHAR(40),
UNIQUE(name)
);
</programlisting>
</para>
</refsect1> </refsect1>
<refsect1 id="R1-SQL-CREATETABLE-3"> <refsect1 id="SQL-CREATETABLE-compatibility">
<title> <title id="SQL-CREATETABLE-compatibility-title">Compatibility</title>
Compatibility
</title> <para>
The <command>CREATE TABLE</command> conforms to SQL92 Intermediate
<refsect2 id="R2-SQL-CREATETABLE-4"> and to a subset of SQL99, with exceptions listed below and in the
<title> descriptions above.
SQL92 </para>
</title>
<refsect2>
<title>Temporary Tables</title>
<para> <para>
In addition to the locally visible temporary table, SQL92 also defines a In addition to the local temporary table, SQL92 also defines a
CREATE GLOBAL TEMPORARY TABLE statement, and optionally an <literal>CREATE GLOBAL TEMPORARY TABLE</literal> statement.
ON COMMIT clause: Global temporary tables are also visible to other sessions.
<synopsis>
CREATE GLOBAL TEMPORARY TABLE <replaceable class="parameter">table</replaceable> ( <replaceable class="parameter">column</replaceable> <replaceable class="parameter">type</replaceable> [
DEFAULT <replaceable class="parameter">value</replaceable> ] [ CONSTRAINT <replaceable class="parameter">column_constraint</replaceable> ] [, ... ] )
[ CONSTRAINT <replaceable class="parameter">table_constraint</replaceable> ] [ ON COMMIT { DELETE | PRESERVE } ROWS ]
</synopsis>
</para> </para>
<para> <para>
For temporary tables, the CREATE GLOBAL TEMPORARY TABLE statement For temporary tables, there is an optional <literal>ON COMMIT</literal> clause:
names a new table visible to other clients and defines the table's columns <synopsis>
and constraints. CREATE { GLOBAL | LOCAL } TEMPORARY TABLE <replaceable class="parameter">table</replaceable> ( <replaceable class="parameter">...</replaceable> ) [ ON COMMIT { DELETE | PRESERVE } ROWS ]
</synopsis>
The <literal>ON COMMIT</literal> clause specifies whether or not
the temporary table should be emptied of rows whenever
<command>COMMIT</command> is executed. If the <literal>ON
COMMIT</> clause is omitted, SQL92 specifies that the default is
<literal>ON COMMIT DELETE ROWS</>. However, the behavior of
<productname>PostgreSQL</productname> is always like <literal>ON
COMMIT PRESERVE ROWS</literal>.
</para> </para>
</refsect2>
<refsect2>
<title><literal>NULL</literal> <quote>Constraint</quote></title>
<para> <para>
The optional ON COMMIT clause of CREATE TEMPORARY TABLE specifies The <literal>NULL</> <quote>constraint</quote> (actually a
whether or not the temporary table should be emptied of rows non-constraint) is a <productname>PostgreSQL</productname>
whenever COMMIT is executed. If the ON COMMIT clause is omitted, SQL92 extension to SQL92 that is included for compatibility with some
specifies that the default is ON COMMIT DELETE ROWS. However, other RDBMSes (and for symmetry with the <literal>NOT
<productname>Postgres</productname>' behavior is always like NULL</literal> constraint). Since it is the default for any
ON COMMIT PRESERVE ROWS. column, its presence is simply noise.
</para> </para>
</refsect2>
<refsect2>
<title>Assertions</title>
<refsect3 id="R3-SQL-UNIQUECLAUSE-1"> <para>
<title> An assertion is a special type of integrity constraint and shares
UNIQUE clause the same namespace as other constraints. However, an assertion is
</title> not necessarily dependent on one particular table as constraints
<para> are, so SQL92 provides the <command>CREATE ASSERTION</command>
SQL92 specifies some additional capabilities for UNIQUE: statement as an alternate method for defining a constraint:
</para>
<para>
Table Constraint definition:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] UNIQUE ( <replaceable>column</replaceable> [, ... ] )
[ { INITIALLY DEFERRED | INITIALLY IMMEDIATE } ]
[ [ NOT ] DEFERRABLE ]
</synopsis>
</para>
<para> <synopsis>
Column Constraint definition: CREATE ASSERTION <replaceable>name</replaceable> CHECK ( <replaceable>condition</replaceable> )
</synopsis>
</para>
<synopsis> <para>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] UNIQUE <productname>PostgreSQL</> does not implement assertions at present.
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ] </para>
[ [ NOT ] DEFERRABLE ] </refsect2>
</synopsis>
</para>
</refsect3>
<refsect3 id="R3-SQL-NULL-1">
<title>
NULL clause
</title>
<para>
The NULL <quote>constraint</quote> (actually a non-constraint) is a
<productname>Postgres</productname> extension to SQL92 that is
included for symmetry with the NOT NULL clause (and for compatibility
with some other RDBMSes). Since it is the
default for any column, its presence is simply noise.
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] NULL
</synopsis>
</para>
</refsect3>
<refsect3 id="R3-SQL-NOTNULL-4">
<title>
NOT NULL clause
</title>
<para>
SQL92 specifies some additional capabilities for NOT NULL:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] NOT NULL
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
[ [ NOT ] DEFERRABLE ]
</synopsis>
</para>
</refsect3>
<!--
I can't figure out why DEFAULT clause is different from what we already have.
Perhaps because CURRENT_USER and CURRENT_DATE have specific types (currently
the <type>name</type> type), if you aren't careful then the types won't match up with
the column. Not our problem...
- Thomas 1998-08-16
<REFSECT3 ID="R3-SQL-DEFAULTCLAUSE-1">
<TITLE>
DEFAULT clause
</TITLE>
<PARA>
SQL92 specifies some additional capabilities for the DEFAULT clause.
A DEFAULT clause is used to set the default value for a column
or a domain.
</para>
<synopsis>
DEFAULT niladic_user_function | niladic_datetime_function | NULL
</synopsis>
</refsect3>
-->
<refsect3 id="R3-SQL-CONSTRAINT-3"> <!--
<title>
CONSTRAINT clause
</title>
<para>
SQL92 specifies some additional capabilities for constraints,
and also defines assertions and domain constraints.
<note>
<para>
<productname>Postgres</productname> does not yet support
either domains or assertions.
</para>
</note>
</para>
<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 SQL-92 provides the CREATE ASSERTION statement
as an alternate method for defining a constraint:
</para>
<synopsis>
CREATE ASSERTION <replaceable>name</replaceable> CHECK ( <replaceable>condition</replaceable> )
</synopsis>
<para> <para>
Domain constraints are defined by CREATE DOMAIN or ALTER DOMAIN Domain constraints are defined by CREATE DOMAIN or ALTER DOMAIN
statements: statements:
...@@ -1984,191 +830,38 @@ CREATE ASSERTION <replaceable>name</replaceable> CHECK ( <replaceable>condition< ...@@ -1984,191 +830,38 @@ CREATE ASSERTION <replaceable>name</replaceable> CHECK ( <replaceable>condition<
[ [ NOT ] DEFERRABLE ] [ [ NOT ] DEFERRABLE ]
</synopsis> </synopsis>
</para> </para>
<para>
Table constraint definition:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] { PRIMARY KEY ( <replaceable class="parameter">column</replaceable>, ... ) | FOREIGN KEY <replaceable>constraint</replaceable> | UNIQUE <replaceable>constraint</replaceable> | CHECK <replaceable>constraint</replaceable> }
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
[ [ NOT ] DEFERRABLE ]
</synopsis>
</para>
<para>
Column constraint definition:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] { NOT NULL | PRIMARY KEY | FOREIGN KEY <replaceable>constraint</replaceable> | UNIQUE | CHECK <replaceable>constraint</replaceable> }
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
[ [ NOT ] DEFERRABLE ]
</synopsis>
</para>
<para>
A CONSTRAINT definition may contain one deferment attribute
clause and/or one initial constraint mode clause, in any order.
<variablelist>
<varlistentry>
<term>NOT DEFERRABLE</term>
<listitem>
<para>
The constraint must be checked at the end of each statement.
SET CONSTRAINTS ALL DEFERRED will have no effect on this type
of constraint.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>DEFERRABLE</term>
<listitem>
<para>
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.
</para>
<note>
<para>
<command>SET CONSTRAINTS</> changes the foreign key constraint mode
only for the current transaction.
</para>
</note>
</listitem>
</varlistentry>
<varlistentry>
<term>INITIALLY IMMEDIATE</term>
<listitem>
<para>
Check constraint after each statement. This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>INITIALLY DEFERRED</term>
<listitem>
<para>
Check constraint only at the end of the transaction.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3 id="R3-SQL-CHECK-4">
<title>
CHECK clause
</title>
<para>
SQL92 specifies some additional capabilities for CHECK in either
table or column constraints.
</para>
<!--
Constraints associated with domains do not need to be mentioned here,
even though it is the case that a domain constraint may possibly
affect a column or a table.
- Thomas 1998-08-16
<para>
A CHECK constraint is either a table constraint, a column
constraint or a domain constraint.
</para>
--> -->
<para>
table constraint definition: <refsect2>
<synopsis> <title>Inheritance</title>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ]
CHECK ( VALUE <replaceable>condition</replaceable> )
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
[ [ NOT ] DEFERRABLE ]
</synopsis>
</para>
<para>
column constraint definition:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ]
CHECK ( VALUE <replaceable>condition</replaceable> )
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
[ [ NOT ] DEFERRABLE ]
</synopsis>
</para>
<!--
<para> <para>
domain constraint definition: Multiple inheritance via the <literal>INHERITS</literal> clause is
</para> a <productname>PostgreSQL</productname> language extension. SQL99
<synopsis> (but not SQL92) defines single inheritance using a different
[ CONSTRAINT name] syntax and different semantics. SQL99-style inheritance is not
CHECK ( VALUE condition ) yet supported by <productname>PostgreSQL</productname>.
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ] </para>
[ [ NOT ] DEFERRABLE ] </refsect2>
</synopsis>
<para>
CHECK domain constraints can be defined in either
a CREATE DOMAIN statement or an ALTER DOMAIN statement:
</para>
<programlisting>
CREATE DOMAIN duration AS SMALLINT
CONSTRAINT minutes CHECK (VALUE IN (90,120,180,240));
ALTER DOMAIN cities <refsect2>
ADD CONSTRAINT new_city CHECK (VALUE LIKE 'L%'); <title>Object IDs</title>
</programlisting>
-->
</refsect3>
<refsect3 id="R3-SQL-PRIMARYKEY-1"> <para>
<title> The <productname>PostgreSQL</productname> concept of OIDs is not
PRIMARY KEY clause standard.
</title> </para>
<para> </refsect2>
SQL92 specifies some additional capabilities for PRIMARY KEY: </refsect1>
</para>
<para>
Table Constraint definition:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] PRIMARY KEY ( <replaceable>column</replaceable> [, ... ] )
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
[ [ NOT ] DEFERRABLE ]
</synopsis>
</para>
<para>
Column Constraint definition:
<synopsis>
[ CONSTRAINT <replaceable>constraint_name</replaceable> ] PRIMARY KEY
[ {INITIALLY DEFERRED | INITIALLY IMMEDIATE} ]
[ [ NOT ] DEFERRABLE ]
</synopsis>
</para>
</refsect3>
<refsect3 id="R3-SQL-INHERITANCE-1">
<title>
Inheritance
</title>
<para>
Multiple inheritance via the INHERITS clause is a
<productname>Postgres</productname> language extension.
SQL99 (but not SQL92) defines single inheritance using a different
syntax and different semantics. SQL99-style inheritance is not yet
supported by <productname>Postgres</productname>.
</para>
</refsect3>
<refsect3 id="R3-SQL-OBJECTIDS-1"> <refsect1>
<title> <title>See Also</title>
Object IDs
</title> <simplelist type="inline">
<para> <member><xref linkend="sql-altertable"></member>
The <productname>Postgres</productname> concept of OIDs is not <member><xref linkend="sql-droptable"></member>
standard. SQL99 (but not SQL92) has a notion of object ID, but </simplelist>
the syntax and semantics are different --- SQL99 associates OIDs
with individual values, not with rows.
</para>
</refsect3>
</refsect2>
</refsect1> </refsect1>
</refentry> </refentry>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.7 2001/09/03 12:57:49 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.8 2001/10/22 18:14:47 petere Exp $
Postgres documentation Postgres documentation
--> -->
<refentry id="SQL-CREATETABLEAS"> <refentry id="SQL-CREATETABLEAS">
<refmeta> <refmeta>
<refentrytitle id="SQL-CREATETABLEAS-TITLE"> <refentrytitle>CREATE TABLE AS</refentrytitle>
CREATE TABLE AS
</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo> <refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta> </refmeta>
<refnamediv> <refnamediv>
<refname> <refname>CREATE TABLE AS</refname>
CREATE TABLE AS <refpurpose>create a new table from the results of a query</refpurpose>
</refname>
<refpurpose>
create a new table from the results of a query
</refpurpose>
</refnamediv> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
<refsynopsisdivinfo> <synopsis>
<date>2001-03-03</date> CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name</replaceable> [ (<replaceable>column_name</replaceable> [, ...] ) ]
</refsynopsisdivinfo> AS <replaceable>query</replaceable>
<synopsis>
CREATE [ TEMPORARY | TEMP ] TABLE <replaceable>table</replaceable> [ (<replaceable>column</replaceable> [, ...] ) ]
AS <replaceable>select_clause</replaceable>
</synopsis> </synopsis>
<refsect2>
<refsect2info>
<date>1998-09-22</date>
</refsect2info>
<title>
Inputs
</title>
<para>
<variablelist>
<varlistentry>
<term>TEMPORARY or TEMP</term>
<listitem>
<para>
If specified, the table is created only within this session, and is
automatically dropped on session exit.
Existing permanent tables with the same name are not visible
(in this session) while the temporary table exists.
Any indexes created on a temporary table are automatically
temporary as well.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>table</replaceable></term>
<listitem>
<para>
The name of the new table to be created.
This table must not already exist. However, a temporary table
can be created that has the same name as an existing permanent
table.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>column</replaceable></term>
<listitem>
<para>
The name of a column. Multiple column names can be specified using
a comma-delimited list of column names. If column names are not
provided, they are taken from the output column names of the
SELECT query.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>select_clause</replaceable></term>
<listitem>
<para>
A valid query statement. Refer to
<xref linkend="sql-select" endterm="sql-select-title">
for a description of the allowed syntax.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
<refsect2>
<refsect2info>
<date>1998-09-22</date>
</refsect2info>
<title>
Outputs
</title>
<para>
Refer to
<xref linkend="sql-createtable" endterm="sql-createtable-title">
and
<xref linkend="sql-select" endterm="sql-select-title">
for a summary of possible output messages.
</para>
</refsect2>
</refsynopsisdiv> </refsynopsisdiv>
<refsect1> <refsect1>
<refsect1info> <refsect1info>
<date>2001-03-20</date> <date>2001-03-20</date>
...@@ -117,28 +31,135 @@ CREATE [ TEMPORARY | TEMP ] TABLE <replaceable>table</replaceable> [ (<replaceab ...@@ -117,28 +31,135 @@ CREATE [ TEMPORARY | TEMP ] TABLE <replaceable>table</replaceable> [ (<replaceab
<para> <para>
<command>CREATE TABLE AS</command> creates a table and fills it <command>CREATE TABLE AS</command> creates a table and fills it
with data computed by a <command>SELECT</command> command. The with data computed by a <command>SELECT</command> command. The
table columns have the names and datatypes associated with the table columns have the names and data types associated with the
output columns of the <command>SELECT</command> (except that you output columns of the <command>SELECT</command> (except that you
can override the <command>SELECT</command> column names by giving can override the column names by giving an explicit list of new
an explicit list of column names). column names).
</para>
<para>
<command>CREATE TABLE AS</command> bears some resemblance to
creating a view, but it is really quite different: it creates a new
table and evaluates the query just once to fill the new table
initially. The new table will not track subsequent changes to the
source tables of the query. In contrast, a view re-evaluates the
underlying <command>SELECT</command> statements whenever it is
queried.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><literal>[LOCAL] TEMPORARY</> or <literal>[LOCAL] TEMP</></term>
<listitem>
<para>
If specified, the table is created as a temporary table.
Temporary tables are automatically dropped at the end of a
session. Existing persistent tables with the same name are not
visible to the current session while the temporary table exists.
Any indexes created on a temporary table are automatically
temporary as well.
</para>
<para>
The <literal>LOCAL</literal> word is optional.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>table_name</replaceable></term>
<listitem>
<para>
The name of the new table to be created. This table must not
already exist. However, a temporary table can be created that
has the same name as an existing permanent table.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>column_name</replaceable></term>
<listitem>
<para>
The name of a column in the new table. Multiple column names can
be specified using a comma-delimited list of column names. If
column names are not provided, they are taken from the output
column names of the query.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>query</replaceable></term>
<listitem>
<para>
A query statement (that is, a <command>SELECT</command>
command). Refer to
<xref linkend="sql-select">
for a description of the allowed syntax.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Diagnostics</title>
<para>
Refer to <xref linkend="sql-createtable"> and
<xref linkend="sql-select">
for a summary of possible output messages.
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>
This command is functionally equivalent to <xref
linkend="sql-selectinto">, but it is preferred since it is less
likely to be confused with other uses of the <command>SELECT
... INTO</command> syntax.
</para> </para>
</refsect1>
<refsect1>
<title>Compatibility</title>
<para> <para>
<command>CREATE TABLE AS</command> bears some resemblance to creating This command is modeled after an <productname>Oracle</productname>
a view, but it is really quite different: it creates a new table and feature. There is no command with equivalent functionality in
evaluates the <command>SELECT</command> just once to fill the new table SQL92 or SQL99. However, a combination of <literal>CREATE
initially. The new table will not track subsequent changes to TABLE</literal> and <literal>INSERT ... SELECT</literal> can
the source tables of the <command>SELECT</command>. In contrast, accomplish the same thing with little more effort.
a view re-evaluates the given <command>SELECT</command> whenever queried.
</para> </para>
</refsect1>
<refsect1>
<title>History</title>
<para> <para>
This command is functionally equivalent to The <command>CREATE TABLE AS</command> command has been available
<xref linkend="sql-selectinto" endterm="sql-selectinto-title">, since <productname>PostgreSQL</productname> 6.3.
but it is preferred since it is less likely to be confused with
other uses of the <command>SELECT ... INTO</command> syntax.
</para> </para>
</refsect1> </refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-createtable"></member>
<member><xref linkend="sql-createview"></member>
<member><xref linkend="sql-select"></member>
<member><xref linkend="sql-selectinto"></member>
</simplelist>
</refsect1>
</refentry> </refentry>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.12 2001/09/23 13:34:44 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.13 2001/10/22 18:14:47 petere Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -89,7 +89,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be: ...@@ -89,7 +89,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
<para> <para>
All other inputs are described in detail for All other inputs are described in detail for
<xref linkend="sql-select" endterm="sql-select-title">. <xref linkend="sql-select">.
</para> </para>
</refsect2> </refsect2>
...@@ -103,9 +103,9 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be: ...@@ -103,9 +103,9 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
<para> <para>
Refer to Refer to
<xref linkend="sql-createtable" endterm="sql-createtable-title"> <xref linkend="sql-createtable">
and and
<xref linkend="sql-select" endterm="sql-select-title"> <xref linkend="sql-select">
for a summary of possible output messages. for a summary of possible output messages.
</para> </para>
</refsect2> </refsect2>
...@@ -128,7 +128,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be: ...@@ -128,7 +128,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
<note> <note>
<para> <para>
<xref linkend="sql-createtableas" endterm="sql-createtableas-title"> <xref linkend="sql-createtableas">
is functionally equivalent to <command>SELECT INTO</command>. is functionally equivalent to <command>SELECT INTO</command>.
<command>CREATE TABLE AS</command> is the recommended syntax, since <command>CREATE TABLE AS</command> is the recommended syntax, since
<command>SELECT INTO</command> is not standard. In fact, this form of <command>SELECT INTO</command> is not standard. In fact, this form of
......
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/stylesheet.dsl,v 1.14 2001/10/09 18:46:00 petere Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/stylesheet.dsl,v 1.15 2001/10/22 18:14:47 petere Exp $ -->
<!DOCTYPE style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN" [ <!DOCTYPE style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN" [
<!-- must turn on one of these with -i on the jade command line --> <!-- must turn on one of these with -i on the jade command line -->
...@@ -123,6 +123,16 @@ ...@@ -123,6 +123,16 @@
;;; XXX The above is very ugly. It might be better to run 'tidy' on ;;; XXX The above is very ugly. It might be better to run 'tidy' on
;;; the resulting *.html files. ;;; the resulting *.html files.
;; Format multiple terms in varlistentry vertically, instead
;; of comma-separated.
(element (varlistentry term)
(make sequence
(process-children-trim)
(if (not (last-sibling?))
(make empty-element gi: "BR")
(empty-sosofo))))
]]> <!-- %output-html --> ]]> <!-- %output-html -->
<![ %output-print; [ <![ %output-print; [
......
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