public inbox for [email protected]
help / color / mirror / Atom feedFrom: Chao Li <[email protected]>
To: David G. Johnston <[email protected]>
Cc: Zsolt Parragi <[email protected]>
Cc: Postgres hackers <[email protected]>
Cc: Amit Kapila <[email protected]>
Subject: Re: docs: clarify ALTER TABLE behavior on partitioned tables
Date: Thu, 29 Jan 2026 09:43:40 +0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAKFQuwa9E+k_VekEeP1syJg2qAzTLGcO6qexPAuMZeSEZE9-QA@mail.gmail.com>
References: <CAEoWx2=mYhCfsnHaN96Qqwq5b0GVS2YgO3zpVqPPRd_iO52wRw@mail.gmail.com>
<[email protected]>
<CAKFQuwbWNCX1M1e9_-3P9RVGo10huPjuqdL74FJ+-a5EW791KA@mail.gmail.com>
<[email protected]>
<CAKFQuwZ+o6La5DyK9_-L2gpeiKNvGMbR78UjocO4++JkyZaRHw@mail.gmail.com>
<[email protected]>
<CAKFQuwabxFyFQob=RfKOV3upjxwomAzmGzSouN-h2ypuXz+dZg@mail.gmail.com>
<[email protected]>
<CAKFQuwZaquUrTOhfmJ2CenwiyAHx4nORQ0kB01sL+z5pCBuLFQ@mail.gmail.com>
<CAEoWx2mUiCYJEBuo5D74gi7pHfNz82b54oDHjZNtrXRFDnBPOg@mail.gmail.com>
<CAKFQuwbQ=L8w8jEaB8_gW-RrNv2_V-VrFYBump7__z-vh-QJWw@mail.gmail.com>
<CAEoWx2nwoBtWX3=UOQQpGZOuRH5vNv2PHqeFHqDPdiKGaOigiA@mail.gmail.com>
<CAKFQuwZyJNBN+N5Qtcg0aG6ZpOFvQV5m=cALLgv7g3u1Sz-tZw@mail.gmail.com>
<[email protected]>
<CAKFQuwZr_GLBOOLohfEcKVVTcP9D+nzVdUUKabYbXWXRnOFjnA@mail.gmail.com>
<CAEoWx2=CK=QEvpL5HSgFEuFqjO2Q1sDy6a2G-s-+zv+RzB3mTw@mail.gmail.com>
<CAN4CZFNoLSUcVKcOOJgOtTkDuOseCL5j9MQr3tGjb3btD=jHNQ@mail.gmail.com>
<CAKFQuwZwAuO3qXEeqxwV6vM+89BkB-aSkcXqDGG8e_xBy_Q3Xw@mail.gmail.com>
<[email protected]>
<CAKFQuwa9OEJ_sygQi3fNKxzQz7M6V7-zu=4fL0rquXCjudUoyw@mail.gmail.com>
<[email protected]>
<CAKFQuwbXVypHH=tQEGo-PskaOjnaPwheh7m-PBw-4QDd8bJMeg@mail.gmail.com>
<[email protected]>
<CAN4CZFM+vnALQBJ2n9x4njbnm_PQFKXLrPRJ1WYsOUozwz1fsQ@mail.gmail.com>
<[email protected]>
<CAKFQuwa9E+k_VekEeP1syJg2qAzTLGcO6qexPAuMZeSEZE9-QA@mail.gmail.com>
> On Jan 29, 2026, at 06:21, David G. Johnston <[email protected]> wrote:
>
> On Mon, Jan 26, 2026 at 3:42 PM Chao Li <[email protected]> wrote:
>
> PFA v8.
>
>
> Delta:
>
> Added missing literal element for ONLY
Accepted.
> Expanded usage of "propagates" wording and made it active voice
I doubt this change. But as a non-English speaker, I don’t want to argue about English, so, I will just accept the change.
> Fixed wording of "partitioned table and/or partitions" to be more correct and succinct: "parent and individual partitions"
Accepted.
> Modified the 'sequences' wording to try and make it more obvious that every partition has its own sequence that is affected rather than a single sequence for the entire partitioned table.
Accepted.
>
> Note, I think the base patch should have all the isolated newlines-between-para changes removed from it. If anything, the more common, and for me more readable, flow is to have those line breaks. In any case, the file is not consistent on one or the other before or after these unrelated fixes so we shouldn't be making them. For new paragraphs, matching the block they are added in works - and if adding the second paragraph I'd include a newline.
Yeah, I actually inclined to have a newline between paragraphs, but the doc already contains inconsistent styles, so I just tried to follow surrounding paragraphs’ style to decide if a new line needed.
>
> Note, the convention is to use two spaces after a full stop (period). Not too worried about this one here, just an FYI.
>
Thanks for the information.
PFA v10 - just integrated v9-0002-diff into the patch.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
[application/octet-stream] v10-0001-docs-clarify-ALTER-TABLE-behavior-on-partitioned.patch (33.6K, 2-v10-0001-docs-clarify-ALTER-TABLE-behavior-on-partitioned.patch)
download | inline diff:
From 28e1e3c09d835777baaba85f6059b93ea677e3b2 Mon Sep 17 00:00:00 2001
From: Chao Li <[email protected]>
Date: Wed, 7 Jan 2026 14:50:36 -0700
Subject: [PATCH v10] docs: clarify ALTER TABLE behavior on partitioned tables
Document how individual ALTER TABLE sub-commands behave when applied to
partitioned tables.
The existing ALTER TABLE documentation provides limited or incomplete
information about how commands interact with partitioned tables, leaving
users to infer behavior from experimentation. This patch systematically
clarifies, for each relevant sub-command, whether changes propagate to
existing partitions, can be applied independently to partitions, and
how the ONLY keyword behaves.
In addition, clarify in CREATE TABLE documentation which parent table
settings are inherited by newly created partitions and which are not.
This makes explicit that while most definition-level properties are
inherited from the partitioned table, certain per-relation settings
(such as ownership, schema, replica identity, row-level security, and
per-attribute statistics/options) are not, unless explicitly specified.
No behavior is changed by this patch; it is purely a documentation update
intended to make existing semantics explicit and easier to understand.
Author: Chao Li <[email protected]>
Author: David G. Johnston <[email protected]>
Reviewed-by: David G. Johnston <[email protected]>
Reviewed-by: Zsolt Parragi <[email protected]>
Discussion: https://postgr.es/m/CAEoWx2=mYhCfsnHaN96Qqwq5b0GVS2YgO3zpVqPPRd_iO52wRw@mail.gmail.com
---
doc/src/sgml/ref/alter_table.sgml | 310 ++++++++++++++++++++---------
doc/src/sgml/ref/create_table.sgml | 7 +
2 files changed, 227 insertions(+), 90 deletions(-)
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 1bd479c917a..f5ce556dafd 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -171,6 +171,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
is specified and a column already exists with this name,
no error is thrown.
</para>
+ <para>
+ When applied to a partitioned table, the column is added to the
+ partitioned table definition and is implicitly added to all
+ partitions. Specifying <literal>ONLY</literal> is not allowed, and
+ this command cannot be used on individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -190,6 +196,18 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
does not exist, no error is thrown. In this case a notice
is issued instead.
</para>
+ <para>
+ When applied to a partitioned table, the column is removed from the
+ partitioned table definition and is implicitly removed from all
+ partitions. Specifying <literal>ONLY</literal> is not allowed, and
+ this command cannot be used on individual partitions.
+ </para>
+ <para>
+ For inheritance setups, a descendant column is removed only if all the
+ following are true: <literal>ONLY</literal> is not specified, no other
+ parent defines the column, and the column is not marked as having been independent.
+ Otherwise, the descendant column is instead marked as having been independent.
+ </para>
</listitem>
</varlistentry>
@@ -211,7 +229,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
clause must be provided if there is no implicit or assignment
cast from old to new type.
</para>
-
<para>
When this form is used, the column's statistics are removed,
so running <link linkend="sql-analyze"><command>ANALYZE</command></link>
@@ -219,6 +236,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
For a virtual generated column, <command>ANALYZE</command>
is not necessary because such columns never have statistics.
</para>
+ <para>
+ When applied to a partitioned table, the data type change is applied
+ to the partitioned table definition and is implicitly applied to all
+ partitions. Specifying <literal>ONLY</literal> is not allowed,
+ and this command cannot be used on individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -232,6 +255,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
or <command>UPDATE</command> commands; it does not cause rows already
in the table to change.
</para>
+ <para>
+ When applied to a partitioned table, the default value propagates
+ to all partitions unless <literal>ONLY</literal> is specified.
+ </para>
</listitem>
</varlistentry>
@@ -242,7 +269,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
These forms change whether a column is marked to allow null
values or to reject null values.
</para>
-
<para>
<literal>SET NOT NULL</literal> may only be applied to a column
provided none of the records in the table contain a
@@ -255,18 +281,18 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
If a column has an invalid not-null constraint,
<literal>SET NOT NULL</literal> validates it.
</para>
-
<para>
- If this table is a partition, one cannot perform <literal>DROP NOT NULL</literal>
- on a column if it is marked <literal>NOT NULL</literal> in the parent
- table. To drop the <literal>NOT NULL</literal> constraint from all the
- partitions, perform <literal>DROP NOT NULL</literal> on the parent
- table. Even if there is no <literal>NOT NULL</literal> constraint on the
- parent, such a constraint can still be added to individual partitions,
- if desired; that is, the children can disallow nulls even if the parent
- allows them, but not the other way around. It is also possible to drop
- the <literal>NOT NULL</literal> constraint from <literal>ONLY</literal>
- the parent table, which does not remove it from the children.
+ If this table is a partition, one cannot perform
+ <literal>DROP NOT NULL</literal> on a column if it is marked
+ <literal>NOT NULL</literal> in the parent table. To drop the
+ <literal>NOT NULL</literal> constraint from all partitions, perform
+ <literal>DROP NOT NULL</literal> on the parent table. Even if there is
+ no <literal>NOT NULL</literal> constraint on the parent, such a
+ constraint can still be added to individual partitions; that is, the
+ children can disallow nulls even if the parent allows them, but not
+ the other way around. It is also possible to apply
+ <literal>SET NOT NULL</literal> or <literal>DROP NOT NULL</literal> to
+ <literal>ONLY</literal> the parent table.
</para>
</listitem>
</varlistentry>
@@ -279,7 +305,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
in a stored generated column is rewritten and all the future changes
will apply the new generation expression.
</para>
-
<para>
When this form is used on a stored generated column, its statistics
are removed, so running
@@ -288,6 +313,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
For a virtual generated column, <command>ANALYZE</command>
is not necessary because such columns never have statistics.
</para>
+ <para>
+ When applied to a partitioned table, the generation expression
+ propagates to all partitions unless <literal>ONLY</literal>
+ is specified.
+ </para>
</listitem>
</varlistentry>
@@ -299,17 +329,20 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
Existing data in the columns is retained, but future changes will no
longer apply the generation expression.
</para>
-
<para>
This form is currently only supported for stored generated columns (not
virtual ones).
</para>
-
<para>
If <literal>DROP EXPRESSION IF EXISTS</literal> is specified and the
column is not a generated column, no error is thrown. In this case a
notice is issued instead.
</para>
+ <para>
+ When applied to a partitioned table, the generation expression is
+ removed from all partitions. Specifying <literal>ONLY</literal> is not
+ allowed, and this command cannot be used on individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -327,12 +360,16 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
and <command>UPDATE</command> commands; they do not cause rows
already in the table to change.
</para>
-
<para>
If <literal>DROP IDENTITY IF EXISTS</literal> is specified and the
column is not an identity column, no error is thrown. In this case a
notice is issued instead.
</para>
+ <para>
+ When applied to a partitioned table, the action propagates to all partitions.
+ Specifying <literal>ONLY</literal> is not allowed, and these forms
+ cannot be used on individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -346,6 +383,13 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
supported by <link linkend="sql-altersequence"><command>ALTER SEQUENCE</command></link> such
as <literal>INCREMENT BY</literal>.
</para>
+ <para>
+ When applied to a partitioned table, these forms alter the sequences
+ associated with the identity column on the partitioned table
+ and those on individual partitions. Specifying <literal>ONLY</literal>
+ is not allowed, and these forms cannot be used on individual
+ partitions.
+ </para>
</listitem>
</varlistentry>
@@ -369,6 +413,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<literal>SET STATISTICS</literal> acquires a
<literal>SHARE UPDATE EXCLUSIVE</literal> lock.
</para>
+ <para>
+ For partitioned tables, this action propagates to all partitions
+ unless <literal>ONLY</literal> is specified.
+ </para>
</listitem>
</varlistentry>
@@ -403,6 +451,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
Changing per-attribute options acquires a
<literal>SHARE UPDATE EXCLUSIVE</literal> lock.
</para>
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ these forms must be applied separately to the parent table and partitions.
+ </para>
</listitem>
</varlistentry>
@@ -437,6 +489,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
during future table updates.
See <xref linkend="storage-toast"/> for more information.
</para>
+ <para>
+ When applied to a partitioned table, the storage setting propagates
+ to all existing partitions unless <literal>ONLY</literal> is specified.
+ </para>
</listitem>
</varlistentry>
@@ -467,6 +523,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
consulting the <xref linkend="guc-default-toast-compression"/> setting
at the time of data insertion to determine the method to use.
</para>
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ the compression method must be applied separately to the parent table
+ and partitions.
+ </para>
</listitem>
</varlistentry>
@@ -479,7 +540,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
VALID</literal>, which is currently only allowed for foreign-key,
<literal>CHECK</literal>, and not-null constraints.
</para>
-
<para>
Normally, this form will cause a scan of the table to verify that all
existing rows in the table satisfy the new constraint. But if
@@ -495,7 +555,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
See <xref linkend="sql-altertable-notes"/> below for more information
about using the <literal>NOT VALID</literal> option.
</para>
-
<para>
Although most forms of <literal>ADD
<replaceable class="parameter">table_constraint</replaceable></literal>
@@ -506,12 +565,19 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
referenced table, in addition to the lock on the table on which the
constraint is declared.
</para>
-
<para>
Additional restrictions apply when unique or primary key constraints
are added to partitioned tables; see <link linkend="sql-createtable"><command>CREATE TABLE</command></link>.
</para>
-
+ <para>
+ When applied to a partitioned table, the constraint is added to the
+ partitioned table and is implicitly added to all partitions.
+ Specifying <literal>ONLY</literal> is not allowed.
+ </para>
+ <para>
+ For inheritance setups, the constraint is not added to child tables unless it is
+ a <literal>CHECK</literal> constraint that is inheritable (that is, not declared <literal>NO INHERIT</literal>).
+ </para>
</listitem>
</varlistentry>
@@ -523,7 +589,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
constraint to a table based on an existing unique index. All the
columns of the index will be included in the constraint.
</para>
-
<para>
The index cannot have expression columns nor be a partial index.
Also, it must be a b-tree index with default sort ordering. These
@@ -531,7 +596,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
built by a regular <literal>ADD PRIMARY KEY</literal> or <literal>ADD UNIQUE</literal>
command.
</para>
-
<para>
If <literal>PRIMARY KEY</literal> is specified, and the index's columns are not
already marked <literal>NOT NULL</literal>, then this command will attempt to
@@ -539,13 +603,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
That requires a full table scan to verify the column(s) contain no
nulls. In all other cases, this is a fast operation.
</para>
-
<para>
If a constraint name is provided then the index will be renamed to match
the constraint name. Otherwise the constraint will be named the same as
the index.
</para>
-
<para>
After this command is executed, the index is <quote>owned</quote> by the
constraint, in the same way as if the index had been built by
@@ -553,11 +615,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
command. In particular, dropping the constraint will make the index
disappear too.
</para>
-
<para>
- This form is not currently supported on partitioned tables.
+ This form is not supported on partitioned tables, but can be used on
+ individual partitions.
</para>
-
<note>
<para>
Adding a constraint using an existing index can be helpful in
@@ -578,6 +639,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
created. Currently only foreign key constraints may be altered in
this fashion, but see below.
</para>
+ <para>
+ When applied to a partitioned table, the constraint alterations
+ propagate to all partitions.
+ Specifying <literal>ONLY</literal> is not allowed, and this command
+ cannot be used on individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -596,7 +663,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
non-inheritable on a table with children, then the corresponding
constraint on children will be marked as no longer inherited,
but not removed.
- </para>
+ </para>
+ <para>
+ These forms are not supported on partitioned tables, but can be used
+ on individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -615,6 +686,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<para>
This command acquires a <literal>SHARE UPDATE EXCLUSIVE</literal> lock.
</para>
+ <para>
+ When applied to a partitioned table, validation propogates to all partitions.
+ Unlike most constraint-related sub-commands, individual partitions may
+ validate the constraint independently of the partitioned table,
+ so long as the partitioned table itself is not yet validated.
+ </para>
</listitem>
</varlistentry>
@@ -627,6 +704,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
If <literal>IF EXISTS</literal> is specified and the constraint
does not exist, no error is thrown. In this case a notice is issued instead.
</para>
+ <para>
+ When applied to a partitioned table, the constraint is dropped from
+ all partitions unless <literal>ONLY</literal> is specified.
+ Dropping an inherited constraint from an individual partition is not allowed.
+ </para>
</listitem>
</varlistentry>
@@ -648,7 +730,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
of course the integrity of the constraint cannot be guaranteed if the
triggers are not executed.
</para>
-
<para>
The trigger firing mechanism is also affected by the configuration
variable <xref linkend="guc-session-replication-role"/>. Simply enabled
@@ -658,7 +739,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
mode, and triggers configured as <literal>ENABLE ALWAYS</literal> will
fire regardless of the current replication role.
</para>
-
<para>
The effect of this mechanism is that in the default configuration,
triggers do not fire on replicas. This is useful because if a trigger
@@ -670,13 +750,15 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
to <literal>ENABLE ALWAYS</literal> so that it is also fired on
replicas.
</para>
-
<para>
When this command is applied to a partitioned table, the states of
- corresponding clone triggers in the partitions are updated too,
- unless <literal>ONLY</literal> is specified.
+ corresponding clone triggers are updated too, unless <literal>ONLY</literal>
+ is specified.
+ </para>
+ <para>
+ For inheritance setups <literal>ONLY</literal> is implied, though it may
+ be specified.
</para>
-
<para>
This command acquires a <literal>SHARE ROW EXCLUSIVE</literal> lock.
</para>
@@ -694,12 +776,15 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
are always applied in order to keep views working even if the current
session is in a non-default replication role.
</para>
-
<para>
The rule firing mechanism is also affected by the configuration variable
<xref linkend="guc-session-replication-role"/>, analogous to triggers as
described above.
</para>
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ these forms must be applied separately to the parent table and individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -715,6 +800,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
See also
<link linkend="sql-createpolicy"><command>CREATE POLICY</command></link>.
</para>
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ these forms must be applied separately to the parent table and individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -730,6 +819,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
See also
<link linkend="sql-createpolicy"><command>CREATE POLICY</command></link>.
</para>
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ this form must be applied separately to the parent table and individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -744,6 +837,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<para>
Changing cluster options acquires a <literal>SHARE UPDATE EXCLUSIVE</literal> lock.
</para>
+ <para>
+ This form is not supported on partitioned tables, but can be used on
+ individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -759,6 +856,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<para>
Changing cluster options acquires a <literal>SHARE UPDATE EXCLUSIVE</literal> lock.
</para>
+ <para>
+ This form is not supported on partitioned tables, but can be used on
+ individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -786,11 +887,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
</para>
<para>
When applied to a partitioned table, there is no data to rewrite,
- but partitions created afterwards will default to the given access
- method unless overridden by a <literal>USING</literal> clause.
- Specifying <varname>DEFAULT</varname> removes a previous value,
- causing future partitions to default to
- <varname>default_table_access_method</varname>.
+ only the default for newly created partitions is changed.
+ Specifying <literal>DEFAULT</literal> removes a previously set access method,
+ causing future partitions to use <varname>default_table_access_method</varname>.
+ Individual partitions are affected just like a regular table.
</para>
</listitem>
</varlistentry>
@@ -803,12 +903,9 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
moves the data file(s) associated with the table to the new tablespace.
Indexes on the table, if any, are not moved; but they can be moved
separately with additional <literal>SET TABLESPACE</literal> commands.
- When applied to a partitioned table, nothing is moved, but any
- partitions created afterwards with
- <command>CREATE TABLE PARTITION OF</command> will use that tablespace,
- unless overridden by a <literal>TABLESPACE</literal> clause.
+ When applied to a partitioned table, no data is moved, only the default
+ for newly created partitions is changed.
</para>
-
<para>
All tables in the current database in a tablespace can be moved by using
the <literal>ALL IN TABLESPACE</literal> form, which will lock all tables
@@ -835,15 +932,14 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
(see <xref linkend="sql-createtable-unlogged"/>). It cannot be applied
to a temporary table.
</para>
-
<para>
This also changes the persistence of any sequences linked to the table
(for identity or serial columns). However, it is also possible to
change the persistence of such sequences separately.
</para>
-
<para>
- This form is not supported for partitioned tables.
+ This form is not supported on partitioned tables, but can be used on
+ individual partitions.
</para>
</listitem>
</varlistentry>
@@ -865,12 +961,15 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
time the table is locked so currently executing queries will not be
affected.
</para>
-
<para>
<literal>SHARE UPDATE EXCLUSIVE</literal> lock will be taken for
fillfactor, TOAST and autovacuum storage parameters, as well as the
planner parameter <varname>parallel_workers</varname>.
</para>
+ <para>
+ This form is not supported on partitioned tables, but can be used on
+ individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -882,6 +981,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
defaults. As with <literal>SET</literal>, a table rewrite might be
needed to update the table entirely.
</para>
+ <para>
+ When applied to a partitioned table, this form is accepted but has no
+ practical effect. It can be used on individual partitions, where it
+ behaves as for a regular table.
+ </para>
</listitem>
</varlistentry>
@@ -895,7 +999,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
already contain all the same columns as the parent (it could have
additional columns, too). The columns must have matching data types.
</para>
-
<para>
In addition, all <literal>CHECK</literal> and <literal>NOT NULL</literal>
constraints on the parent must also exist on the child, except those
@@ -907,6 +1010,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<literal>FOREIGN KEY</literal> constraints are not considered, but
this might change in the future.
</para>
+ <para>
+ This form does not support partitioned tables; it cannot be applied to
+ either a partitioned table or its partitions.
+ </para>
</listitem>
</varlistentry>
@@ -919,6 +1026,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
Queries against the parent table will no longer include records drawn
from the target table.
</para>
+ <para>
+ This form does not support partitioned tables; it cannot be applied to
+ either a partitioned table or its partitions.
+ </para>
</listitem>
</varlistentry>
@@ -933,6 +1044,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
that <command>CREATE TABLE OF</command> would permit an equivalent table
definition.
</para>
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ and this form cannot be used on individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -942,6 +1057,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<para>
This form dissociates a typed table from its type.
</para>
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ and this form cannot be used on individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -952,6 +1071,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
This form changes the owner of the table, sequence, view, materialized view,
or foreign table to the specified user.
</para>
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ this form must be applied separately to the parent table and individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -1008,6 +1131,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
</listitem>
</varlistentry>
</variablelist></para>
+
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ this form must be applied independently to the parent table and individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -1022,6 +1150,18 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
the index is renamed as well.
There is no effect on the stored data.
</para>
+ <para>
+ When applied to a partitioned table’s name, only the parent is changed,
+ partitions must be renamed separately. In contrast, column or constraint
+ renaming must be done on the parent without <literal>ONLY</literal>, the
+ corresponding partition columns or constraints will be renamed implicitly.
+ </para>
+ <para>
+ For inheritance setups, the behavior described for partitioned tables applies
+ only to the dependent column(s) on the descendant table(s). It is always
+ allowed to target a descendant table with column altering commands on independent
+ columns.
+ </para>
</listitem>
</varlistentry>
@@ -1032,6 +1172,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
This form moves the table into another schema. Associated indexes,
constraints, and sequences owned by table columns are moved as well.
</para>
+ <para>
+ When applied to a partitioned table, <literal>ONLY</literal> is implicit,
+ this form must be applied independently to the parent table and individual partitions.
+ </para>
</listitem>
</varlistentry>
@@ -1410,6 +1554,27 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<literal>*</literal> can be specified after the table name to explicitly
indicate that descendant tables are included.
</para>
+
+ <para>
+ For a table that uses table inheritance, descendant tables are those
+ that inherit from the named table, directly or indirectly.
+ For a partitioned table, descendant tables are its partitions.
+ </para>
+
+ <para>
+ Note that for partitioned tables, <literal>ONLY</literal> does not control
+ recursion for all <command>ALTER TABLE</command> actions. Some actions
+ apply only to the partitioned table itself, regardless of whether
+ <literal>ONLY</literal> is specified, while others propagate to
+ partitions. The exact behavior depends on the specific action being
+ performed.
+ </para>
+
+ <para>
+ Users should consult the documentation of each individual
+ <command>ALTER TABLE</command> action to determine whether and how it
+ affects partitions.
+ </para>
</listitem>
</varlistentry>
@@ -1768,45 +1933,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
</para>
<para>
- If a table has any descendant tables, it is not permitted to add,
- rename, or change the type of a column in the parent table without doing
- the same to the descendants. This ensures that the descendants always
- have columns matching the parent. Similarly, a <literal>CHECK</literal>
- constraint cannot be renamed in the parent without also renaming it in
- all descendants, so that <literal>CHECK</literal> constraints also match
- between the parent and its descendants. (That restriction does not apply
- to index-based constraints, however.)
- Also, because selecting from the parent also selects from its descendants,
- a constraint on the parent cannot be marked valid unless it is also marked
- valid for those descendants. In all of these cases, <command>ALTER TABLE
- ONLY</command> will be rejected.
- </para>
-
- <para>
- A recursive <literal>DROP COLUMN</literal> operation will remove a
- descendant table's column only if the descendant does not inherit
- that column from any other parents and never had an independent
- definition of the column. A nonrecursive <literal>DROP
- COLUMN</literal> (i.e., <command>ALTER TABLE ONLY ... DROP
- COLUMN</command>) never removes any descendant columns, but
- instead marks them as independently defined rather than inherited.
- A nonrecursive <literal>DROP COLUMN</literal> command will fail for a
- partitioned table, because all partitions of a table must have the same
- columns as the partitioning root.
- </para>
-
- <para>
- The actions for identity columns (<literal>ADD
- GENERATED</literal>, <literal>SET</literal> etc., <literal>DROP
- IDENTITY</literal>), as well as the actions
- <literal>CLUSTER</literal>, <literal>OWNER</literal>,
- and <literal>TABLESPACE</literal> never recurse to descendant tables;
- that is, they always act as though <literal>ONLY</literal> were specified.
- Actions affecting trigger states recurse to partitions of partitioned
- tables (unless <literal>ONLY</literal> is specified), but never to
- traditional-inheritance descendants.
- Adding a constraint recurses only for <literal>CHECK</literal> constraints
- that are not marked <literal>NO INHERIT</literal>.
+ For inheritance setups, the behavior described for partitioned tables applies
+ only to the dependent column(s) on the descendant table(s). It is always
+ allowed to target a descendant table with column altering commands on independent
+ columns.
</para>
<para>
diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml
index 77c5a763d45..2fcab0d874e 100644
--- a/doc/src/sgml/ref/create_table.sgml
+++ b/doc/src/sgml/ref/create_table.sgml
@@ -633,6 +633,13 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
concurrent operations on the partitioned table.
</para>
+ <para>
+ When a partition is created, it inherits many of the properties
+ of the parent table. However, properties related to ownership,
+ schema, replica identity, row-level security configuration,
+ per-attribute statistics targets, and per-attribute options
+ are not inherited.
+ </para>
</listitem>
</varlistentry>
--
2.50.1 (Apple Git-155)
view thread (19+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: docs: clarify ALTER TABLE behavior on partitioned tables
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox