INHERITS is a PostgreSQL specific clause used in CREATE TABLE and ALTER TABLE statements to implement table inheritance. A child table defined with INHERITS physically stores its own rows but automatically includes the column definitions and CHECK constraints of each listed parent. Queries against a parent can optionally return rows from its descendants when the configuration setting enable_inheritances is on or when the SQL keyword ONLY is omitted. Inherited columns keep their data types and default values unless overridden in the child. Indexes, foreign keys, triggers, and NOT NULL constraints are not inherited and must be re-declared on the child if required. Inheritance is different from partitioning: it is purely a schema design feature, not an automatic data placement mechanism. Dropping a parent does not drop its children, but altering a parent to add or drop a column is immediately visible in all descendants.
child_table_name identifier
- Name of the table being created or alteredcolumn_definitions list
- Columns specific to the child tableparent_table_list
(list) - One or more existing tables to inherit fromCREATE TABLE, ALTER TABLE, ONLY keyword, table partitioning, CHECK constraint, polymorphic queries
PostgreSQL 6.5
All columns and their default values from each parent are automatically present in the child. You can add extra columns in the child as needed.
Yes. Every CHECK constraint defined on a parent is enforced on the child unless it is explicitly dropped from the child.
Yes. PostgreSQL supports multiple inheritance, and the child will include the combined columns and CHECK constraints from all parents. Conflicting column names are not allowed.
Use ALTER TABLE child_table NO INHERITS parent_table; to detach the child from the specified parent.