partitioned tables and their
partitions never share an inheritance hierarchy with regular tables.
</para>
<para>
Since a partition hierarchy consisting of the partitioned table and its
partitions is still an inheritance hierarchy,
<structfield>tableoid</structfield> and all the normal rules of
inheritance apply as described in <xref linkend="ddl-inherit"/>, with
a few exceptions:
<itemizedlist>
<listitem>
<para>
Partitions cannot have columns that are not present in the parent. It
is not possible to specify columns when creating partitions with
<command>CREATE TABLE</command>, nor is it possible to add columns to
partitions after-the-fact using <command>ALTER TABLE</command>.
Tables may be added as a partition with <command>ALTER TABLE
... ATTACH PARTITION</command> only if their columns exactly match
the parent.
</para>
</listitem>
<listitem>
<para>
Both <literal>CHECK</literal> and <literal>NOT NULL</literal>
constraints of a partitioned table are always inherited by all its
partitions; it is not allowed to create <literal>NO INHERIT</literal>
constraints of those types.
You cannot drop a constraint of those types if the same constraint
is present in the parent table.
</para>
</listitem>
<listitem>
<para>
Using <literal>ONLY</literal> to add or drop a constraint on only
the partitioned table is supported as long as there are no
partitions. Once partitions exist, using <literal>ONLY</literal>
will result in an error for any constraints other than
<literal>UNIQUE</literal> and <literal>PRIMARY KEY</literal>.
Instead, constraints on the partitions
themselves can be added and (if they are not present in the parent
table) dropped.
</para>
</listitem>
<listitem>
<para>
As a partitioned table does not have any data itself, attempts to use
<command>TRUNCATE</command> <literal>ONLY</literal> on a partitioned
table will always return an error.
</para>
</listitem>
</itemizedlist>
</para>
</sect3>
</sect2>
<sect2 id="ddl-partitioning-using-inheritance">
<title>Partitioning Using Inheritance</title>
<para>
While the built-in declarative partitioning is suitable for most
common use cases, there are some circumstances where a more flexible
approach may be useful. Partitioning can be implemented using table
inheritance, which allows for several features not supported
by declarative partitioning, such as:
<itemizedlist>
<listitem>
<para>
For declarative partitioning, partitions must have exactly the same set
of columns as the partitioned table, whereas with table inheritance,
child tables may have extra columns not present in the parent.
</para>
</listitem>
<listitem>
<para>
Table inheritance allows for multiple inheritance.
</para>
</listitem>
<listitem>
<para>
Declarative partitioning only supports range, list and hash
partitioning, whereas table inheritance allows data to be divided in a
manner of the user's choosing. (Note, however, that if constraint
exclusion is unable to prune child tables effectively, query performance
might be poor.)
</para>
</listitem>
</itemizedlist>
</para>
<sect3 id="ddl-partitioning-inheritance-example">
<title>Example</title>
<para>
This example builds a partitioning structure equivalent to the
declarative partitioning example above. Use
the following steps:
<orderedlist spacing="compact">
<listitem>
<para>
Create the <quote>root</quote> table, from which all of the
<quote>child</quote>