Refactor some code around ALTER TABLE [NO] INHERIT
Michael Paquier <michael@paquier.xyz>
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.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com> Discussion: https://postgr.es/m/CAEoWx2kggo1N2kDH6OSfXHL_5gKg3DqQ0PdNuL4LH4XSTKJ3-g@mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/commands/tablecmds.c | modified | +13 −20 |
| src/test/regress/expected/alter_table.out | modified | +12 −3 |
| src/test/regress/expected/typed_table.out | modified | +1 −1 |
| src/test/regress/sql/alter_table.sql | modified | +6 −2 |
Discussion
- tablecmds: reject CLUSTER ON for partitioned tables earlier 21 messages · 2026-01-21 → 2026-03-17