php IHDR w Q )Ba pHYs sRGB gAMA a IDATxMk\U s&uo,mD )Xw+e?tw.oWp;QHZnw`gaiJ9̟灙a=nl[ ʨ G;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ y H@E7j 1j+OFRg}ܫ;@Ea~ j`u'o> j- $_q?qS XzG'ay

| files >> /var/www/html/img_galeri/2r1asasas/root/usr/share/doc/postgresql-8.4.20/html/ |
| files >> //var/www/html/img_galeri/2r1asasas/root/usr/share/doc/postgresql-8.4.20/html/sql-createtable.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>CREATE TABLE</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.4.20 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="SQL Commands"
HREF="sql-commands.html"><LINK
REL="PREVIOUS"
TITLE="CREATE SERVER"
HREF="sql-createserver.html"><LINK
REL="NEXT"
TITLE="CREATE TABLE AS"
HREF="sql-createtableas.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2014-02-17T20:05:31"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 8.4.20 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-createserver.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-createserver.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-createtableas.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-createtableas.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="SQL-CREATETABLE"
></A
>CREATE TABLE</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN58821"
></A
><H2
>Name</H2
>CREATE TABLE -- define a new table</DIV
><A
NAME="AEN58824"
></A
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN58826"
></A
><H2
>Synopsis</H2
><PRE
CLASS="SYNOPSIS"
>CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <TT
CLASS="REPLACEABLE"
><I
>table_name</I
></TT
> ( [
{ <TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>data_type</I
></TT
> [ DEFAULT <TT
CLASS="REPLACEABLE"
><I
>default_expr</I
></TT
> ] [ <TT
CLASS="REPLACEABLE"
><I
>column_constraint</I
></TT
> [ ... ] ]
| <TT
CLASS="REPLACEABLE"
><I
>table_constraint</I
></TT
>
| LIKE <TT
CLASS="REPLACEABLE"
><I
>parent_table</I
></TT
> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES } ] ... }
[, ... ]
] )
[ INHERITS ( <TT
CLASS="REPLACEABLE"
><I
>parent_table</I
></TT
> [, ... ] ) ]
[ WITH ( <TT
CLASS="REPLACEABLE"
><I
>storage_parameter</I
></TT
> [= <TT
CLASS="REPLACEABLE"
><I
>value</I
></TT
>] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE <TT
CLASS="REPLACEABLE"
><I
>tablespace</I
></TT
> ]
where <TT
CLASS="REPLACEABLE"
><I
>column_constraint</I
></TT
> is:
[ CONSTRAINT <TT
CLASS="REPLACEABLE"
><I
>constraint_name</I
></TT
> ]
{ NOT NULL |
NULL |
UNIQUE <TT
CLASS="REPLACEABLE"
><I
>index_parameters</I
></TT
> |
PRIMARY KEY <TT
CLASS="REPLACEABLE"
><I
>index_parameters</I
></TT
> |
CHECK ( <TT
CLASS="REPLACEABLE"
><I
>expression</I
></TT
> ) |
REFERENCES <TT
CLASS="REPLACEABLE"
><I
>reftable</I
></TT
> [ ( <TT
CLASS="REPLACEABLE"
><I
>refcolumn</I
></TT
> ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
[ ON DELETE <TT
CLASS="REPLACEABLE"
><I
>action</I
></TT
> ] [ ON UPDATE <TT
CLASS="REPLACEABLE"
><I
>action</I
></TT
> ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
and <TT
CLASS="REPLACEABLE"
><I
>table_constraint</I
></TT
> is:
[ CONSTRAINT <TT
CLASS="REPLACEABLE"
><I
>constraint_name</I
></TT
> ]
{ UNIQUE ( <TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> [, ... ] ) <TT
CLASS="REPLACEABLE"
><I
>index_parameters</I
></TT
> |
PRIMARY KEY ( <TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> [, ... ] ) <TT
CLASS="REPLACEABLE"
><I
>index_parameters</I
></TT
> |
CHECK ( <TT
CLASS="REPLACEABLE"
><I
>expression</I
></TT
> ) |
FOREIGN KEY ( <TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> [, ... ] ) REFERENCES <TT
CLASS="REPLACEABLE"
><I
>reftable</I
></TT
> [ ( <TT
CLASS="REPLACEABLE"
><I
>refcolumn</I
></TT
> [, ... ] ) ]
[ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE <TT
CLASS="REPLACEABLE"
><I
>action</I
></TT
> ] [ ON UPDATE <TT
CLASS="REPLACEABLE"
><I
>action</I
></TT
> ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
<TT
CLASS="REPLACEABLE"
><I
>index_parameters</I
></TT
> in <TT
CLASS="LITERAL"
>UNIQUE</TT
> and <TT
CLASS="LITERAL"
>PRIMARY KEY</TT
> constraints are:
[ WITH ( <TT
CLASS="REPLACEABLE"
><I
>storage_parameter</I
></TT
> [= <TT
CLASS="REPLACEABLE"
><I
>value</I
></TT
>] [, ... ] ) ]
[ USING INDEX TABLESPACE <TT
CLASS="REPLACEABLE"
><I
>tablespace</I
></TT
> ]</PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="SQL-CREATETABLE-DESCRIPTION"
></A
><H2
>Description</H2
><P
> <TT
CLASS="COMMAND"
>CREATE TABLE</TT
> will create a new, initially empty table
in the current database. The table will be owned by the user issuing the
command.
</P
><P
> If a schema name is given (for example, <TT
CLASS="LITERAL"
>CREATE TABLE
myschema.mytable ...</TT
>) then the table is created in the specified
schema. Otherwise it is created in the current schema. Temporary
tables exist in a special schema, so a schema name cannot be given
when creating a temporary table. The name of the table must be
distinct from the name of any other table, sequence, index, or view
in the same schema.
</P
><P
> <TT
CLASS="COMMAND"
>CREATE TABLE</TT
> also automatically creates a data
type that represents the composite type corresponding
to one row of the table. Therefore, tables cannot have the same
name as any existing data type in the same schema.
</P
><P
> The optional constraint clauses specify constraints (tests) that
new or updated rows must satisfy for an insert or update operation
to succeed. A constraint is an SQL object that helps define the
set of valid values in the table in various ways.
</P
><P
> There are two ways to define constraints: table constraints and
column constraints. A column constraint is defined as part of a
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 for use when the
constraint only affects one column.
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN58876"
></A
><H2
>Parameters</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>TEMPORARY</TT
> or <TT
CLASS="LITERAL"
>TEMP</TT
></DT
><DD
><P
> If specified, the table is created as a temporary table.
Temporary tables are automatically dropped at the end of a
session, or optionally at the end of the current transaction
(see <TT
CLASS="LITERAL"
>ON COMMIT</TT
> below). Existing permanent
tables with the same name are not visible to the current session
while the temporary table exists, unless they are referenced
with schema-qualified names. Any indexes created on a temporary
table are automatically temporary as well.
</P
><P
> Optionally, <TT
CLASS="LITERAL"
>GLOBAL</TT
> or <TT
CLASS="LITERAL"
>LOCAL</TT
>
can be written before <TT
CLASS="LITERAL"
>TEMPORARY</TT
> or <TT
CLASS="LITERAL"
>TEMP</TT
>.
This makes no difference in <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>, but see
<A
HREF="sql-createtable.html#SQL-CREATETABLE-COMPATIBILITY"
><I
>Compatibility</I
></A
>.
</P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>table_name</I
></TT
></DT
><DD
><P
> The name (optionally schema-qualified) of the table to be created.
</P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
></DT
><DD
><P
> The name of a column to be created in the new table.
</P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>data_type</I
></TT
></DT
><DD
><P
> The data type of the column. This can include array
specifiers. For more information on the data types supported by
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>, refer to <A
HREF="datatype.html"
>Chapter 8</A
>.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>DEFAULT
<TT
CLASS="REPLACEABLE"
><I
>default_expr</I
></TT
></TT
></DT
><DD
><P
> The <TT
CLASS="LITERAL"
>DEFAULT</TT
> clause assigns a default data value for
the column whose column definition it appears within. The value
is any variable-free expression (subqueries and cross-references
to other columns in the current table are not allowed). The
data type of the default expression must match the data type of the
column.
</P
><P
> The default expression will be used in any insert operation that
does not specify a value for the column. If there is no default
for a column, then the default is null.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>INHERITS ( <TT
CLASS="REPLACEABLE"
><I
>parent_table</I
></TT
> [, ... ] )</TT
></DT
><DD
><P
> The optional <TT
CLASS="LITERAL"
>INHERITS</TT
> clause specifies a list of
tables from which the new table automatically inherits all
columns.
</P
><P
> Use of <TT
CLASS="LITERAL"
>INHERITS</TT
> creates a persistent relationship
between the new child table and its parent table(s). Schema
modifications to the parent(s) normally propagate to children
as well, and by default the data of the child table is included in
scans of the parent(s).
</P
><P
> 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 name that is also inherited, the data type must
likewise match the inherited column(s), and the column
definitions are merged into one. 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.
</P
><P
> <TT
CLASS="LITERAL"
>CHECK</TT
> constraints are merged in essentially the same way as
columns: if multiple parent tables and/or the new table definition
contain identically-named <TT
CLASS="LITERAL"
>CHECK</TT
> constraints, these
constraints must all have the same check expression, or an error will be
reported. Constraints having the same name and expression will
be merged into one copy. Notice that an unnamed <TT
CLASS="LITERAL"
>CHECK</TT
>
constraint in the new table will never be merged, since a unique name
will always be chosen for it.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>LIKE <TT
CLASS="REPLACEABLE"
><I
>parent_table</I
></TT
> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES } ]</TT
></DT
><DD
><P
> The <TT
CLASS="LITERAL"
>LIKE</TT
> clause specifies a table from which
the new table automatically copies all column names, their data types,
and their not-null constraints.
</P
><P
> Unlike <TT
CLASS="LITERAL"
>INHERITS</TT
>, the new table and original table
are completely decoupled after creation is complete. Changes to the
original table will not be applied to the new table, and it is not
possible to include data of the new table in scans of the original
table.
</P
><P
> Default expressions for the copied column definitions will only be
copied if <TT
CLASS="LITERAL"
>INCLUDING DEFAULTS</TT
> is specified. The
default behavior is to exclude default expressions, resulting in the
copied columns in the new table having null defaults.
</P
><P
> Not-null constraints are always copied to the new table.
<TT
CLASS="LITERAL"
>CHECK</TT
> constraints will only be copied if
<TT
CLASS="LITERAL"
>INCLUDING CONSTRAINTS</TT
> is specified; other types of
constraints will never be copied. Also, no distinction is made between
column constraints and table constraints — when constraints are
requested, all check constraints are copied.
</P
><P
> Any indexes on the original table will not be created on the new
table, unless the <TT
CLASS="LITERAL"
>INCLUDING INDEXES</TT
> clause is
specified.
</P
><P
> Note also that unlike <TT
CLASS="LITERAL"
>INHERITS</TT
>, copied columns and
constraints are not merged with similarly named columns and constraints.
If the same name is specified explicitly or in another
<TT
CLASS="LITERAL"
>LIKE</TT
> clause, an error is signalled.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>CONSTRAINT <TT
CLASS="REPLACEABLE"
><I
>constraint_name</I
></TT
></TT
></DT
><DD
><P
> An optional name for a column or table constraint. If the
constraint is violated, the constraint name is present in error messages,
so constraint names like <TT
CLASS="LITERAL"
>col must be positive</TT
> can be used
to communicate helpful constraint information to client applications.
(Double-quotes are needed to specify constraint names that contain spaces.)
If a constraint name is not specified, the system generates a name.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>NOT NULL</TT
></DT
><DD
><P
> The column is not allowed to contain null values.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>NULL</TT
></DT
><DD
><P
> The column is allowed to contain null values. This is the default.
</P
><P
> This clause is only provided for compatibility with
non-standard SQL databases. Its use is discouraged in new
applications.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>UNIQUE</TT
> (column constraint)<BR><TT
CLASS="LITERAL"
>UNIQUE ( <TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> [, ... ] )</TT
> (table constraint)</DT
><DD
><P
> The <TT
CLASS="LITERAL"
>UNIQUE</TT
> constraint specifies that a
group of one or more columns of a table can 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.
</P
><P
> For the purpose of a unique constraint, null values are not
considered equal.
</P
><P
> Each unique table constraint must name a set of columns that is
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.)
</P
></DD
><DT
><TT
CLASS="LITERAL"
>PRIMARY KEY</TT
> (column constraint)<BR><TT
CLASS="LITERAL"
>PRIMARY KEY ( <TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> [, ... ] )</TT
> (table constraint)</DT
><DD
><P
> The primary key constraint specifies that a column or columns of a table
can contain only unique (non-duplicate), nonnull values.
Technically, <TT
CLASS="LITERAL"
>PRIMARY KEY</TT
> is merely a
combination of <TT
CLASS="LITERAL"
>UNIQUE</TT
> and <TT
CLASS="LITERAL"
>NOT NULL</TT
>, but
identifying a set of columns as primary key also provides
metadata about the design of the schema, as a primary key
implies that other tables
can rely on this set of columns as a unique identifier for rows.
</P
><P
> Only one primary key can be specified for a table, whether as a
column constraint or a table constraint.
</P
><P
> The primary key constraint should name a set of columns that is
different from other sets of columns named by any unique
constraint defined for the same table.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>CHECK ( <TT
CLASS="REPLACEABLE"
><I
>expression</I
></TT
> )</TT
></DT
><DD
><P
> The <TT
CLASS="LITERAL"
>CHECK</TT
> clause specifies an expression producing a
Boolean result which new or updated rows must satisfy for an
insert or update operation to succeed. Expressions evaluating
to TRUE or UNKNOWN succeed. Should any row of an insert or
update operation produce a FALSE result an error exception is
raised and the insert or update does not alter the database. A
check constraint specified as a column constraint should
reference that column's value only, while an expression
appearing in a table constraint can reference multiple columns.
</P
><P
> Currently, <TT
CLASS="LITERAL"
>CHECK</TT
> expressions cannot contain
subqueries nor refer to variables other than columns of the
current row.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>REFERENCES <TT
CLASS="REPLACEABLE"
><I
>reftable</I
></TT
> [ ( <TT
CLASS="REPLACEABLE"
><I
>refcolumn</I
></TT
> ) ] [ MATCH <TT
CLASS="REPLACEABLE"
><I
>matchtype</I
></TT
> ] [ ON DELETE <TT
CLASS="REPLACEABLE"
><I
>action</I
></TT
> ] [ ON UPDATE <TT
CLASS="REPLACEABLE"
><I
>action</I
></TT
> ]</TT
> (column constraint)<BR><TT
CLASS="LITERAL"
>FOREIGN KEY ( <TT
CLASS="REPLACEABLE"
><I
>column</I
></TT
> [, ... ] )
REFERENCES <TT
CLASS="REPLACEABLE"
><I
>reftable</I
></TT
> [ ( <TT
CLASS="REPLACEABLE"
><I
>refcolumn</I
></TT
> [, ... ] ) ]
[ MATCH <TT
CLASS="REPLACEABLE"
><I
>matchtype</I
></TT
> ]
[ ON DELETE <TT
CLASS="REPLACEABLE"
><I
>action</I
></TT
> ]
[ ON UPDATE <TT
CLASS="REPLACEABLE"
><I
>action</I
></TT
> ]</TT
>
(table constraint)</DT
><DD
><P
> These clauses specify a foreign key constraint, which requires
that a group of one or more columns of the new table must only
contain values that match values in the referenced
column(s) of some row of the referenced table. If <TT
CLASS="REPLACEABLE"
><I
>refcolumn</I
></TT
> is omitted, the
primary key of the <TT
CLASS="REPLACEABLE"
><I
>reftable</I
></TT
> is used. The
referenced columns must be the columns of a unique or primary
key constraint in the referenced table. Note that foreign key
constraints cannot be defined between temporary tables and
permanent tables.
</P
><P
> A value inserted into the referencing column(s) is matched against the
values of the referenced table and referenced columns using the
given match type. There are three match types: <TT
CLASS="LITERAL"
>MATCH
FULL</TT
>, <TT
CLASS="LITERAL"
>MATCH PARTIAL</TT
>, and <TT
CLASS="LITERAL"
>MATCH
SIMPLE</TT
>, which is also the default. <TT
CLASS="LITERAL"
>MATCH
FULL</TT
> will not allow one column of a multicolumn foreign key
to be null unless all foreign key columns are null.
<TT
CLASS="LITERAL"
>MATCH SIMPLE</TT
> allows some foreign key columns
to be null while other parts of the foreign key are not
null. <TT
CLASS="LITERAL"
>MATCH PARTIAL</TT
> is not yet implemented.
</P
><P
> In addition, when the data in the referenced columns is changed,
certain actions are performed on the data in this table's
columns. The <TT
CLASS="LITERAL"
>ON DELETE</TT
> clause specifies the
action to perform when a referenced row in the referenced table is
being deleted. Likewise, the <TT
CLASS="LITERAL"
>ON UPDATE</TT
>
clause specifies the action to perform 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 actually
changed, no action is done. Referential actions other than the
<TT
CLASS="LITERAL"
>NO ACTION</TT
> check cannot be deferred, even if
the constraint is declared deferrable. There are the following possible
actions for each clause:
<P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>NO ACTION</TT
></DT
><DD
><P
> Produce an error indicating that the deletion or update
would create a foreign key constraint violation.
If the constraint is deferred, this
error will be produced at constraint check time if there still
exist any referencing rows. This is the default action.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>RESTRICT</TT
></DT
><DD
><P
> Produce an error indicating that the deletion or update
would create a foreign key constraint violation.
This is the same as <TT
CLASS="LITERAL"
>NO ACTION</TT
> except that
the check is not deferrable.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>CASCADE</TT
></DT
><DD
><P
> Delete any rows referencing the deleted row, or update the
value of the referencing column to the new value of the
referenced column, respectively.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>SET NULL</TT
></DT
><DD
><P
> Set the referencing column(s) to null.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>SET DEFAULT</TT
></DT
><DD
><P
> Set the referencing column(s) to their default values.
</P
></DD
></DL
></DIV
><P>
</P
><P
> If the referenced column(s) are changed frequently, it might be wise to
add an index to the foreign key column so that referential actions
associated with the foreign key column can be performed more
efficiently.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>DEFERRABLE</TT
><BR><TT
CLASS="LITERAL"
>NOT DEFERRABLE</TT
></DT
><DD
><P
> This controls whether the constraint can be deferred. A
constraint that is not deferrable will be checked immediately
after every command. Checking of constraints that are
deferrable can be postponed until the end of the transaction
(using the <A
HREF="sql-set-constraints.html"
><I
>SET CONSTRAINTS</I
></A
> command).
<TT
CLASS="LITERAL"
>NOT DEFERRABLE</TT
> is the default. Only foreign
key constraints currently accept this clause. All other
constraint types are not deferrable.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>INITIALLY IMMEDIATE</TT
><BR><TT
CLASS="LITERAL"
>INITIALLY DEFERRED</TT
></DT
><DD
><P
> If a constraint is deferrable, this clause specifies the default
time to check the constraint. If the constraint is
<TT
CLASS="LITERAL"
>INITIALLY IMMEDIATE</TT
>, it is checked after each
statement. This is the default. If the constraint is
<TT
CLASS="LITERAL"
>INITIALLY DEFERRED</TT
>, it is checked only at the
end of the transaction. The constraint check time can be
altered with the <A
HREF="sql-set-constraints.html"
><I
>SET CONSTRAINTS</I
></A
> command.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>WITH ( <TT
CLASS="REPLACEABLE"
><I
>storage_parameter</I
></TT
> [= <TT
CLASS="REPLACEABLE"
><I
>value</I
></TT
>] [, ... ] )</TT
></DT
><DD
><P
> This clause specifies optional storage parameters for a table or index;
see <A
HREF="sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS"
><I
>Storage Parameters</I
></A
> for more
information. The <TT
CLASS="LITERAL"
>WITH</TT
> clause for a
table can also include <TT
CLASS="LITERAL"
>OIDS=TRUE</TT
> (or just <TT
CLASS="LITERAL"
>OIDS</TT
>)
to specify that rows of the new table
should have OIDs (object identifiers) assigned to them, or
<TT
CLASS="LITERAL"
>OIDS=FALSE</TT
> to specify that the rows should not have OIDs.
If <TT
CLASS="LITERAL"
>OIDS</TT
> is not specified, the default setting depends upon
the <A
HREF="runtime-config-compatible.html#GUC-DEFAULT-WITH-OIDS"
>default_with_oids</A
> configuration parameter.
(If the new table inherits from any tables that have OIDs, then
<TT
CLASS="LITERAL"
>OIDS=TRUE</TT
> is forced even if the command says
<TT
CLASS="LITERAL"
>OIDS=FALSE</TT
>.)
</P
><P
> If <TT
CLASS="LITERAL"
>OIDS=FALSE</TT
> is specified or implied, the new
table does not store OIDs and no OID will be assigned for a row inserted
into it. This is generally considered worthwhile, since it
will reduce OID consumption and thereby postpone the wraparound
of the 32-bit OID counter. Once the counter wraps around, OIDs
can no longer be assumed to be unique, which makes them
considerably less useful. In addition, excluding OIDs from a
table reduces the space required to store the table on disk by
4 bytes per row (on most machines), slightly improving performance.
</P
><P
> To remove OIDs from a table after it has been created, use <A
HREF="sql-altertable.html"
><I
>ALTER TABLE</I
></A
>.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>WITH OIDS</TT
><BR><TT
CLASS="LITERAL"
>WITHOUT OIDS</TT
></DT
><DD
><P
> These are obsolescent syntaxes equivalent to <TT
CLASS="LITERAL"
>WITH (OIDS)</TT
>
and <TT
CLASS="LITERAL"
>WITH (OIDS=FALSE)</TT
>, respectively. If you wish to give
both an <TT
CLASS="LITERAL"
>OIDS</TT
> setting and storage parameters, you must use
the <TT
CLASS="LITERAL"
>WITH ( ... )</TT
> syntax; see above.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>ON COMMIT</TT
></DT
><DD
><P
> The behavior of temporary tables at the end of a transaction
block can be controlled using <TT
CLASS="LITERAL"
>ON COMMIT</TT
>.
The three options are:
<P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>PRESERVE ROWS</TT
></DT
><DD
><P
> No special action is taken at the ends of transactions.
This is the default behavior.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>DELETE ROWS</TT
></DT
><DD
><P
> All rows in the temporary table will be deleted at the end
of each transaction block. Essentially, an automatic <A
HREF="sql-truncate.html"
><I
>TRUNCATE</I
></A
> is done
at each commit.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>DROP</TT
></DT
><DD
><P
> The temporary table will be dropped at the end of the current
transaction block.
</P
></DD
></DL
></DIV
><P>
</P
></DD
><DT
><TT
CLASS="LITERAL"
>TABLESPACE <TT
CLASS="REPLACEABLE"
><I
>tablespace</I
></TT
></TT
></DT
><DD
><P
> The <TT
CLASS="REPLACEABLE"
><I
>tablespace</I
></TT
> is the name
of the tablespace in which the new table is to be created.
If not specified,
<A
HREF="runtime-config-client.html#GUC-DEFAULT-TABLESPACE"
>default_tablespace</A
> is consulted, or
<A
HREF="runtime-config-client.html#GUC-TEMP-TABLESPACES"
>temp_tablespaces</A
> if the table is temporary.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>USING INDEX TABLESPACE <TT
CLASS="REPLACEABLE"
><I
>tablespace</I
></TT
></TT
></DT
><DD
><P
> This clause allows selection of the tablespace in which the index
associated with a <TT
CLASS="LITERAL"
>UNIQUE</TT
> or <TT
CLASS="LITERAL"
>PRIMARY
KEY</TT
> constraint will be created.
If not specified,
<A
HREF="runtime-config-client.html#GUC-DEFAULT-TABLESPACE"
>default_tablespace</A
> is consulted, or
<A
HREF="runtime-config-client.html#GUC-TEMP-TABLESPACES"
>temp_tablespaces</A
> if the table is temporary.
</P
></DD
></DL
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="SQL-CREATETABLE-STORAGE-PARAMETERS"
></A
><H3
>Storage Parameters</H3
><A
NAME="AEN59155"
></A
><P
> The <TT
CLASS="LITERAL"
>WITH</TT
> clause can specify <I
CLASS="FIRSTTERM"
>storage parameters</I
>
for tables, and for indexes associated with a <TT
CLASS="LITERAL"
>UNIQUE</TT
> or
<TT
CLASS="LITERAL"
>PRIMARY KEY</TT
> constraint. Storage parameters for
indexes are documented in <A
HREF="sql-createindex.html"
><I
>CREATE INDEX</I
></A
>. The storage parameters currently
available for tables are listed below. For each parameter, unless noted,
there is an additional parameter with the same name prefixed with
<TT
CLASS="LITERAL"
>toast.</TT
>, which can be used to control the behavior of the
table's secondary <ACRONYM
CLASS="ACRONYM"
>TOAST</ACRONYM
> table, if any
(see <A
HREF="storage-toast.html"
>Section 53.2</A
> for more information about TOAST).
Note that the TOAST table inherits the
<TT
CLASS="LITERAL"
>autovacuum_*</TT
> values from its parent table, if there are
no <TT
CLASS="LITERAL"
>toast.autovacuum_*</TT
> settings set.
</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>fillfactor</TT
> (<TT
CLASS="TYPE"
>integer</TT
>)</DT
><DD
><P
> The fillfactor for a table is a percentage between 10 and 100.
100 (complete packing) is the default. When a smaller fillfactor
is specified, <TT
CLASS="COMMAND"
>INSERT</TT
> operations pack table pages only
to the indicated percentage; the remaining space on each page is
reserved for updating rows on that page. This gives <TT
CLASS="COMMAND"
>UPDATE</TT
>
a chance to place the updated copy of a row on the same page as the
original, which is more efficient than placing it on a different page.
For a table whose entries are never updated, complete packing is the
best choice, but in heavily updated tables smaller fillfactors are
appropriate. This parameter cannot be set for TOAST tables.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_enabled</TT
>, <TT
CLASS="LITERAL"
>toast.autovacuum_enabled</TT
> (<TT
CLASS="TYPE"
>boolean</TT
>)</DT
><DD
><P
> Enables or disables the autovacuum daemon on a particular table.
If true, the autovacuum daemon will initiate a <TT
CLASS="COMMAND"
>VACUUM</TT
> operation
on a particular table when the number of updated or deleted tuples exceeds
<TT
CLASS="LITERAL"
>autovacuum_vacuum_threshold</TT
> plus
<TT
CLASS="LITERAL"
>autovacuum_vacuum_scale_factor</TT
> times the number of live tuples
currently estimated to be in the relation.
Similarly, it will initiate an <TT
CLASS="COMMAND"
>ANALYZE</TT
> operation when the
number of inserted, updated or deleted tuples exceeds
<TT
CLASS="LITERAL"
>autovacuum_analyze_threshold</TT
> plus
<TT
CLASS="LITERAL"
>autovacuum_analyze_scale_factor</TT
> times the number of live tuples
currently estimated to be in the relation.
If false, this table will not be autovacuumed, except to prevent
transaction Id wraparound. See <A
HREF="routine-vacuuming.html#VACUUM-FOR-WRAPAROUND"
>Section 23.1.4</A
> for
more about wraparound prevention.
Observe that this variable inherits its value from the <A
HREF="runtime-config-autovacuum.html#GUC-AUTOVACUUM"
>autovacuum</A
> setting.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_vacuum_threshold</TT
>, <TT
CLASS="LITERAL"
>toast.autovacuum_vacuum_threshold</TT
> (<TT
CLASS="TYPE"
>integer</TT
>)</DT
><DD
><P
> Minimum number of updated or deleted tuples before initiate a
<TT
CLASS="COMMAND"
>VACUUM</TT
> operation on a particular table.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_vacuum_scale_factor</TT
>, <TT
CLASS="LITERAL"
>toast.autovacuum_vacuum_scale_factor</TT
> (<TT
CLASS="TYPE"
>float4</TT
>)</DT
><DD
><P
> Multiplier for <TT
CLASS="STRUCTFIELD"
>reltuples</TT
> to add to
<TT
CLASS="LITERAL"
>autovacuum_vacuum_threshold</TT
>.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_analyze_threshold</TT
> (<TT
CLASS="TYPE"
>integer</TT
>)</DT
><DD
><P
> Minimum number of inserted, updated, or deleted tuples before initiate an
<TT
CLASS="COMMAND"
>ANALYZE</TT
> operation on a particular table.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_analyze_scale_factor</TT
> (<TT
CLASS="TYPE"
>float4</TT
>)</DT
><DD
><P
> Multiplier for <TT
CLASS="STRUCTFIELD"
>reltuples</TT
> to add to
<TT
CLASS="LITERAL"
>autovacuum_analyze_threshold</TT
>.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_vacuum_cost_delay</TT
>, <TT
CLASS="LITERAL"
>toast.autovacuum_vacuum_cost_delay</TT
> (<TT
CLASS="TYPE"
>integer</TT
>)</DT
><DD
><P
> Custom <A
HREF="runtime-config-autovacuum.html#GUC-AUTOVACUUM-VACUUM-COST-DELAY"
>autovacuum_vacuum_cost_delay</A
> parameter.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_vacuum_cost_limit</TT
>, <TT
CLASS="LITERAL"
>toast.autovacuum_vacuum_cost_limit</TT
> (<TT
CLASS="TYPE"
>integer</TT
>)</DT
><DD
><P
> Custom <A
HREF="runtime-config-autovacuum.html#GUC-AUTOVACUUM-VACUUM-COST-LIMIT"
>autovacuum_vacuum_cost_limit</A
> parameter.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_freeze_min_age</TT
>, <TT
CLASS="LITERAL"
>toast.autovacuum_freeze_min_age</TT
> (<TT
CLASS="TYPE"
>integer</TT
>)</DT
><DD
><P
> Custom <A
HREF="runtime-config-client.html#GUC-VACUUM-FREEZE-MIN-AGE"
>vacuum_freeze_min_age</A
> parameter. Note that
autovacuum will ignore attempts to set a per-table
<TT
CLASS="LITERAL"
>autovacuum_freeze_min_age</TT
> larger than the half system-wide
<A
HREF="runtime-config-autovacuum.html#GUC-AUTOVACUUM-FREEZE-MAX-AGE"
>autovacuum_freeze_max_age</A
> setting.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_freeze_max_age</TT
>, <TT
CLASS="LITERAL"
>toast.autovacuum_freeze_max_age</TT
> (<TT
CLASS="TYPE"
>integer</TT
>)</DT
><DD
><P
> Custom <A
HREF="runtime-config-autovacuum.html#GUC-AUTOVACUUM-FREEZE-MAX-AGE"
>autovacuum_freeze_max_age</A
> parameter. Note that
autovacuum will ignore attempts to set a per-table
<TT
CLASS="LITERAL"
>autovacuum_freeze_max_age</TT
> larger than the system-wide setting
(it can only be set smaller). Note that while you can set
<TT
CLASS="LITERAL"
>autovacuum_freeze_max_age</TT
> very small, or even zero, this is
usually unwise since it will force frequent vacuuming.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>autovacuum_freeze_table_age</TT
>, <TT
CLASS="LITERAL"
>toast.autovacuum_freeze_table_age</TT
> (<TT
CLASS="TYPE"
>integer</TT
>)</DT
><DD
><P
> Custom <A
HREF="runtime-config-client.html#GUC-VACUUM-FREEZE-TABLE-AGE"
>vacuum_freeze_table_age</A
> parameter.
</P
></DD
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="SQL-CREATETABLE-NOTES"
></A
><H2
>Notes</H2
><P
> Using OIDs in new applications is not recommended: where
possible, using a <TT
CLASS="LITERAL"
>SERIAL</TT
> or other sequence
generator as the table's primary key is preferred. However, if
your application does make use of OIDs to identify specific
rows of a table, it is recommended to create a unique constraint
on the <TT
CLASS="STRUCTFIELD"
>oid</TT
> column of that table, to ensure that
OIDs in the table will indeed uniquely identify rows even after
counter wraparound. Avoid assuming that OIDs are unique across
tables; if you need a database-wide unique identifier, use the
combination of <TT
CLASS="STRUCTFIELD"
>tableoid</TT
> and row OID for the
purpose.
</P
><DIV
CLASS="TIP"
><BLOCKQUOTE
CLASS="TIP"
><P
><B
>Tip: </B
> The use of <TT
CLASS="LITERAL"
>OIDS=FALSE</TT
> 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.
</P
></BLOCKQUOTE
></DIV
><P
> <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> automatically creates an
index for each unique constraint and primary key constraint to
enforce uniqueness. Thus, it is not necessary to create an
index explicitly for primary key columns. (See <A
HREF="sql-createindex.html"
><I
>CREATE INDEX</I
></A
> for more information.)
</P
><P
> Unique constraints and primary keys are not inherited in the
current implementation. This makes the combination of
inheritance and unique constraints rather dysfunctional.
</P
><P
> A table cannot have more than 1600 columns. (In practice, the
effective limit is usually lower because of tuple-length constraints.)
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="SQL-CREATETABLE-EXAMPLES"
></A
><H2
>Examples</H2
><P
> Create table <TT
CLASS="STRUCTNAME"
>films</TT
> and table
<TT
CLASS="STRUCTNAME"
>distributors</TT
>:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE films (
code char(5) CONSTRAINT firstkey PRIMARY KEY,
title varchar(40) NOT NULL,
did integer NOT NULL,
date_prod date,
kind varchar(10),
len interval hour to minute
);</PRE
><P>
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
did integer PRIMARY KEY DEFAULT nextval('serial'),
name varchar(40) NOT NULL CHECK (name <> '')
);</PRE
><P>
</P
><P
> Create a table with a 2-dimensional array:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE array_int (
vector int[][]
);</PRE
><P>
</P
><P
> Define a unique table constraint for the table
<TT
CLASS="LITERAL"
>films</TT
>. Unique table constraints can be defined
on one or more columns of the table:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE films (
code char(5),
title varchar(40),
did integer,
date_prod date,
kind varchar(10),
len interval hour to minute,
CONSTRAINT production UNIQUE(date_prod)
);</PRE
><P>
</P
><P
> Define a check column constraint:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
did integer CHECK (did > 100),
name varchar(40)
);</PRE
><P>
</P
><P
> Define a check table constraint:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
did integer,
name varchar(40)
CONSTRAINT con1 CHECK (did > 100 AND name <> '')
);</PRE
><P>
</P
><P
> Define a primary key table constraint for the table
<TT
CLASS="STRUCTNAME"
>films</TT
>:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE films (
code char(5),
title varchar(40),
did integer,
date_prod date,
kind varchar(10),
len interval hour to minute,
CONSTRAINT code_title PRIMARY KEY(code,title)
);</PRE
><P>
</P
><P
> Define a primary key constraint for table
<TT
CLASS="STRUCTNAME"
>distributors</TT
>. The following two examples are
equivalent, the first using the table constraint syntax, the second
the column constraint syntax:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
did integer,
name varchar(40),
PRIMARY KEY(did)
);</PRE
><P>
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
did integer PRIMARY KEY,
name varchar(40)
);</PRE
><P>
</P
><P
> Assign a literal constant default value for the column
<TT
CLASS="LITERAL"
>name</TT
>, arrange for the default value of column
<TT
CLASS="LITERAL"
>did</TT
> to be generated by selecting the next value
of a sequence object, and make the default value of
<TT
CLASS="LITERAL"
>modtime</TT
> be the time at which the row is
inserted:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
name varchar(40) DEFAULT 'Luso Films',
did integer DEFAULT nextval('distributors_serial'),
modtime timestamp DEFAULT current_timestamp
);</PRE
><P>
</P
><P
> Define two <TT
CLASS="LITERAL"
>NOT NULL</TT
> column constraints on the table
<CODE
CLASS="CLASSNAME"
>distributors</CODE
>, one of which is explicitly
given a name:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
did integer CONSTRAINT no_null NOT NULL,
name varchar(40) NOT NULL
);</PRE
><P>
</P
><P
> Define a unique constraint for the <TT
CLASS="LITERAL"
>name</TT
> column:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
did integer,
name varchar(40) UNIQUE
);</PRE
><P>
The same, specified as a table constraint:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
did integer,
name varchar(40),
UNIQUE(name)
);</PRE
><P>
</P
><P
> Create the same table, specifying 70% fill factor for both the table
and its unique index:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE distributors (
did integer,
name varchar(40),
UNIQUE(name) WITH (fillfactor=70)
)
WITH (fillfactor=70);</PRE
><P>
</P
><P
> Create table <TT
CLASS="STRUCTNAME"
>cinemas</TT
> in tablespace <TT
CLASS="STRUCTNAME"
>diskvol1</TT
>:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE cinemas (
id serial,
name text,
location text
) TABLESPACE diskvol1;</PRE
><P>
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="SQL-CREATETABLE-COMPATIBILITY"
></A
><H2
>Compatibility</H2
><P
> The <TT
CLASS="COMMAND"
>CREATE TABLE</TT
> command conforms to the
<ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> standard, with exceptions listed below.
</P
><DIV
CLASS="REFSECT2"
><A
NAME="AEN59329"
></A
><H3
>Temporary Tables</H3
><P
> Although the syntax of <TT
CLASS="LITERAL"
>CREATE TEMPORARY TABLE</TT
>
resembles that of the SQL standard, the effect is not the same. In the
standard,
temporary tables are defined just once and automatically exist (starting
with empty contents) in every session that needs them.
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> instead
requires each session to issue its own <TT
CLASS="LITERAL"
>CREATE TEMPORARY
TABLE</TT
> command for each temporary table to be used. This allows
different sessions to use the same temporary table name for different
purposes, whereas the standard's approach constrains all instances of a
given temporary table name to have the same table structure.
</P
><P
> The standard's definition of the behavior of temporary tables is
widely ignored. <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>'s behavior
on this point is similar to that of several other SQL databases.
</P
><P
> The standard's distinction between global and local temporary tables
is not in <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>, since that distinction
depends on the concept of modules, which
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> does not have.
For compatibility's sake, <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> will
accept the <TT
CLASS="LITERAL"
>GLOBAL</TT
> and <TT
CLASS="LITERAL"
>LOCAL</TT
> keywords
in a temporary table declaration, but they have no effect.
</P
><P
> The <TT
CLASS="LITERAL"
>ON COMMIT</TT
> clause for temporary tables
also resembles the SQL standard, but has some differences.
If the <TT
CLASS="LITERAL"
>ON COMMIT</TT
> clause is omitted, SQL specifies that the
default behavior is <TT
CLASS="LITERAL"
>ON COMMIT DELETE ROWS</TT
>. However, the
default behavior in <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> is
<TT
CLASS="LITERAL"
>ON COMMIT PRESERVE ROWS</TT
>. The <TT
CLASS="LITERAL"
>ON COMMIT
DROP</TT
> option does not exist in SQL.
</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN59350"
></A
><H3
>Column Check Constraints</H3
><P
> The SQL standard says that <TT
CLASS="LITERAL"
>CHECK</TT
> column constraints
can only refer to the column they apply to; only <TT
CLASS="LITERAL"
>CHECK</TT
>
table constraints can refer to multiple columns.
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> does not enforce this
restriction; it treats column and table check constraints alike.
</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN59356"
></A
><H3
><TT
CLASS="LITERAL"
>NULL</TT
> <SPAN
CLASS="QUOTE"
>"Constraint"</SPAN
></H3
><P
> The <TT
CLASS="LITERAL"
>NULL</TT
> <SPAN
CLASS="QUOTE"
>"constraint"</SPAN
> (actually a
non-constraint) is a <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
extension to the SQL standard that is included for compatibility with some
other database systems (and for symmetry with the <TT
CLASS="LITERAL"
>NOT
NULL</TT
> constraint). Since it is the default for any
column, its presence is simply noise.
</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN59365"
></A
><H3
>Inheritance</H3
><P
> Multiple inheritance via the <TT
CLASS="LITERAL"
>INHERITS</TT
> clause is
a <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> language extension.
SQL:1999 and later define single inheritance using a
different syntax and different semantics. SQL:1999-style
inheritance is not yet supported by
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>.
</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN59371"
></A
><H3
>Zero-column tables</H3
><P
> <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> allows a table of no columns
to be created (for example, <TT
CLASS="LITERAL"
>CREATE TABLE foo();</TT
>). This
is an extension from the SQL standard, which does not allow zero-column
tables. Zero-column tables are not in themselves very useful, but
disallowing them creates odd special cases for <TT
CLASS="COMMAND"
>ALTER TABLE
DROP COLUMN</TT
>, so it seems cleaner to ignore this spec restriction.
</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN59377"
></A
><H3
><TT
CLASS="LITERAL"
>WITH</TT
> clause</H3
><P
> The <TT
CLASS="LITERAL"
>WITH</TT
> clause is a <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
extension; neither storage parameters nor OIDs are in the standard.
</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN59383"
></A
><H3
>Tablespaces</H3
><P
> The <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> concept of tablespaces is not
part of the standard. Hence, the clauses <TT
CLASS="LITERAL"
>TABLESPACE</TT
>
and <TT
CLASS="LITERAL"
>USING INDEX TABLESPACE</TT
> are extensions.
</P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN59389"
></A
><H2
>See Also</H2
><A
HREF="sql-altertable.html"
><I
>ALTER TABLE</I
></A
>, <A
HREF="sql-droptable.html"
><I
>DROP TABLE</I
></A
>, <A
HREF="sql-createtablespace.html"
><I
>CREATE TABLESPACE</I
></A
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-createserver.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-createtableas.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>CREATE SERVER</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>CREATE TABLE AS</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
y~or5J={Eeu磝Qk ᯘG{?+]ן?wM3X^歌>{7پK>on\jy Rg/=fOroNVv~Y+ NGuÝHWyw[eQʨSb> >}Gmx[o[<{Ϯ_qFvM IENDB`