CREATE [ TEMPORARY | TEMP ] TABLE table_name (
{ column_name type [ column_constraint [ ... ] ]
| table_constraint } [, ... ]
- ) [ INHERITS ( inherited_table [, ... ] ) ]
+ ) [ INHERITS ( parent_table [, ... ] ) ]
where column_constraint can be:
[ CONSTRAINT constraint_name ]
- inherited_table
+ parent_table
The optional INHERITS clause specifies a list of table
names from which this table automatically inherits all fields.
- If any inherited field name appears more than once,
- reports an error.
-
Postgres automatically allows the created
- table to inherit functions on tables above it in the inheritance
- hierarchy.
existing datatype.
+ A table can have no more than 1600 columns (in practice, the
+ effective limit is lower because of tuple-length constraints).
+ A table cannot have the same name as a system catalog table.
+
+
+
+
+
+ INHERITS Clause
+
+
+INHERITS ( parent_table [, ... ] )
+
+
+
The optional INHERITS
- clause specifies a collection of table names from which this table
- automatically inherits all fields. If any inherited field name
- appears more than once, Postgres reports an error. Postgres automatically
- allows the created table to inherit functions on tables above it in
- the inheritance hierarchy. Inheritance of functions is done according
- to the conventions of the Common Lisp Object System (CLOS).
+ 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.
- A table can have no more than 1600 columns (in practice, the
- effective limit is lower because of tuple-length constraints).
- A table cannot have the same name as a system catalog table.
+ 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.
+
+
+ Postgres automatically allows the created table to inherit functions on
+ tables above it in the inheritance hierarchy; that is, if we create table
+ foo inheriting from bar, then
+ functions that accept the tuple type bar can also be
+ applied to instances of foo. (Currently, this works
+ reliably for functions on the first or only parent table, but not so well
+ for functions on additional parents.)