pgsql: Refactor some code around ALTER TABLE [NO] INHERIT

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Refactor some code around ALTER TABLE [NO] INHERIT
Date: 2026-03-17 05:35:51
Message-ID: E1w2N5q-0007V9-2u@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Refactor some code around ALTER TABLE [NO] INHERIT

[NO] INHERIT is not supported for partitioned tables, but this portion
of tablecmds.c did not apply the same rules as the other sub-commands,
checking the relkind in the execution phase, not the preparation phase.

This commit refactors the code to centralize the relkind and other
checks in the preparation phase for both command patterns, getting rid
of one translatable string on the way. ATT_PARTITIONED_TABLE is
removed from ATSimplePermissions(), and the child relation is checked
the same way for both sub-commands. The ALTER TABLE patterns that now
fail at preparation failed already at execution, hence there should be
no changes from the user perspective except more consistent error
messages generated.

Some comments at the top of ATPrepAddInherit() were incorrect,
CreateInheritance() being the routine checking the columns and
constraints between the parent and its to-be-child.

Author: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Discussion: https://postgr.es/m/CAEoWx2kggo1N2kDH6OSfXHL_5gKg3DqQ0PdNuL4LH4XSTKJ3-g@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1a7ccd2b332d5fafa9bf1121c82693c9a2a57298

Modified Files
--------------
src/backend/commands/tablecmds.c | 33 ++++++++++++-------------------
src/test/regress/expected/alter_table.out | 15 +++++++++++---
src/test/regress/expected/typed_table.out | 2 +-
src/test/regress/sql/alter_table.sql | 8 ++++++--
4 files changed, 32 insertions(+), 26 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-03-17 08:40:27 pgsql: gen_guc_tables.pl: Improve detection of inconsistent data
Previous Message Michael Paquier 2026-03-17 04:26:11 pgsql: Add regression test for ALTER TABLE .. NO INHERIT on typed table