pgsql: Fix ALTER COLUMN ... DROP EXPRESSION with subpartitions

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix ALTER COLUMN ... DROP EXPRESSION with subpartitions
Date: 2026-08-04 07:14:47
Message-ID: E1wr9MN-0000000082p-17BP@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix ALTER COLUMN ... DROP EXPRESSION with subpartitions

Per commit 8bf6ec3ba3a4, a column can be GENERATED only if it is such in
the whole inheritance tree.

For this reason, ATPrepDropExpression refuses to be called with ONLY on
a partitioned table. To detect this, the current implementation checks
whether recurse is set to false and the rel has direct children.

Recursion is implemented with ATSimpleRecursion, which calls ATPrepCmd
with recurse = false for every node in the tree. Inner nodes (for
example a partition which itself has subpartitions) then fail the check,
accidentally preventing the command from working on inheritance trees of
depth > 2.

This commit fixes it by also checking that we're at the top level of the
recursive calls using the recursing parameter, which is always true when
called through ATSimpleRecursion, always false when invoked on the root
rel.

Also, remove a comment claiming that DROP EXPRESSION could be
implemented with some effort. It cannot, as the commit message for
8bf6ec3ba3a4 explains.

Author: Alberto Piai <alberto(dot)piai(at)gmail(dot)com>
Backpatch-through: 14
Discussion: https://postgr.es/m/DHMT78XOD8BK.341V3H87KZ7NO@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fef160d8b0ddf72e1089133300d30109293f5a71

Modified Files
--------------
src/backend/commands/tablecmds.c | 15 +++-----
src/test/regress/expected/generated_stored.out | 51 ++++++++++++++++++++++++++
src/test/regress/sql/generated_stored.sql | 15 ++++++++
3 files changed, 71 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-08-04 08:09:43 pgsql: Fix error handling in getCopyDataMessage() and pqFunctionCall3()
Previous Message David Rowley 2026-08-04 06:02:18 pgsql: Fix missing money overflow checks for INT64_MIN / -1