mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
ALTER TABLE ... ADD/DROPS INHERIT (actually INHERIT / NO INHERIT)
Open items: There were a few tangentially related issues that have come up that I think are TODOs. I'm likely to tackle one or two of these next so I'm interested in hearing feedback on them as well. . Constraints currently do not know anything about inheritance. Tom suggested adding a coninhcount and conislocal like attributes have to track their inheritance status. . Foreign key constraints currently do not get copied to new children (and therefore my code doesn't verify them). I don't think it would be hard to add them and treat them like CHECK constraints. . No constraints at all are copied to tables defined with LIKE. That makes it hard to use LIKE to define new partitions. The standard defines LIKE and specifically says it does not copy constraints. But the standard already has an option called INCLUDING DEFAULTS; we could always define a non-standard extension LIKE table INCLUDING CONSTRAINTS that gives the user the option to request a copy including constraints. . Personally, I think the whole attislocal thing is bunk. The decision about whether to drop a column from children tables or not is something that should be up to the user and trying to DWIM based on whether there was ever a local definition or the column was acquired purely through inheritance is hardly ever going to match up with user expectations. . And of course there's the whole unique and primary key constraint issue. I think to get any traction at all on this you have a prerequisite of a real partitioned table implementation where the system knows what the partition key is so it can recognize when it's a leading part of an index key. Greg Stark
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.84 2006/02/12 19:11:00 momjian Exp $
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.85 2006/07/02 01:58:36 momjian Exp $
|
||||
PostgreSQL documentation
|
||||
-->
|
||||
|
||||
@@ -46,6 +46,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
CLUSTER ON <replaceable class="PARAMETER">index_name</replaceable>
|
||||
SET WITHOUT CLUSTER
|
||||
SET WITHOUT OIDS
|
||||
INHERIT <replaceable class="PARAMETER">parent_table</replaceable>
|
||||
NO INHERIT <replaceable class="PARAMETER">parent_table</replaceable>
|
||||
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
|
||||
SET TABLESPACE <replaceable class="PARAMETER">new_tablespace</replaceable>
|
||||
</synopsis>
|
||||
@@ -249,6 +251,52 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>INHERIT <replaceable class="PARAMETER">parent_table</replaceable></literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
|
||||
This form adds a new parent table to the table. This won't add new
|
||||
columns to the child table, instead all columns of the parent table must
|
||||
already exist in the child table. They must have matching data types,
|
||||
and if they have <literal>NOT NULL</literal> constraints in the parent
|
||||
then they must also have <literal>NOT NULL</literal> constraints in the
|
||||
child.
|
||||
|
||||
</para>
|
||||
<para>
|
||||
|
||||
There must also be matching table constraints for all
|
||||
<literal>CHECK</literal> table constraints of the parent. Currently
|
||||
<literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, and
|
||||
<literal>FOREIGN KEY</literal> constraints are ignored however this may
|
||||
change in the future.
|
||||
|
||||
</para>
|
||||
<para>
|
||||
|
||||
The easiest way to create a suitable table is to create a table using
|
||||
<literal>INHERITS</literal> and then remove it via <literal>NO
|
||||
INHERIT</literal>. Alternatively create a table using
|
||||
<literal>LIKE</literal> however note that <literal>LIKE</literal> does
|
||||
not create the necessary constraints.
|
||||
|
||||
</para>
|
||||
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>NO INHERIT <replaceable class="PARAMETER">parent_table</replaceable></literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This form removes a parent table from the list of parents of the table.
|
||||
Queries against the parent table will no longer include records drawn
|
||||
from the target table.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>OWNER</literal></term>
|
||||
<listitem>
|
||||
|
||||
Reference in New Issue
Block a user