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 <[email protected]>
Backpatch-through: 14
Discussion: https://postgr.es/m/[email protected]

Branch
------
REL_18_STABLE

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

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

Reply via email to