ALTER COLUMN TYPE, ALTER TYPE ... ALTER ATTRIBUTE ... TYPE and ALTER COLUMN SET EXPRESSION fail with internal error "unexpected object depending on column" when another table's partition key selects a field of the altered rowtype ===================================================================================================================================================================================================================================== AI-generated bug report from the AI Annex Report ID: 01a1e670-4a7d-7400-96fb-397ca26b0ac0 Filed: 2026-11-16 22:18:01 UTC Severity: 35/100 Blamed commit: f3ea3e3e820b6b7512e48660bf984603418d53ff ## Summary When a partitioned table's partition key expression selects a field of a table's rowtype (or of a standalone composite type), the partitioned table records a pg_depend entry on that column. ALTER TABLE ... ALTER COLUMN TYPE, ALTER TYPE ... ALTER ATTRIBUTE ... TYPE, and ALTER COLUMN ... SET EXPRESSION then fail with an internal XX000 error instead of a user-facing one. The field may be reached through a rowtype constant or through a function returning the rowtype; the latter is not caught by any later rowtype check either. ## Reproduction create table attbl(a numeric); create table atref(b text) partition by range ((('(1)'::attbl).a + length(b))); alter table attbl alter column a type bigint; -- ERROR: XX000: unexpected object depending on column: -- table atref Function-mediated variant (no rowtype constant): create table attbl(a numeric); create function mk(text) returns attbl immutable language sql as $$ select row(length($1))::public.attbl $$; create table atref(b text) partition by range (((mk(b)).a)); alter table attbl alter column a type bigint; -- same error Standalone composite type: create type ct as (a numeric); create function mk(text) returns ct immutable language sql as $$ select row(length($1))::public.ct $$; create table atref(b text) partition by range (((mk(b)).a)); alter type ct alter attribute a type bigint; -- same error SET EXPRESSION on a generated column: create table attbl(x int, a int generated always as (x*2) stored); create function mk(text) returns attbl immutable language sql as $$ select row(length($1), 0)::public.attbl $$; create table atref(b text) partition by range (((mk(b)).a + length(b))); alter table attbl alter column a set expression as (x*3); -- same error Expected: a user-facing error (e.g. "cannot alter type of a column used in a partition key expression"), as for indexes and CHECK constraints that use the rowtype; SET EXPRESSION, which cannot change the column type, could be allowed. ## Analysis RememberAllDependentForRebuilding() in src/backend/commands/tablecmds.c handles RelationRelationId dependents only for indexes and sequences and raises elog(ERROR, "unexpected object depending on column") for any other relkind. A partitioned table whose partition key contains a FieldSelect on the altered rowtype has such a dependency: find_expr_references_walker() records a column dependency for FieldSelect since commit f3ea3e3e820b6b7512e48660bf984603418d53ff ("Fix some oversights in expression dependency recording"), which is when this path became reachable. For tables with storage, find_composite_type_dependencies() runs only later at rewrite time, and it never sees the function-mediated form, so the column dependency is the only guard; the error therefore belongs in RememberAllDependentForRebuilding(). ## Notes Tested on master 7fc2f0423320e02beb8c44b863f1827604c47c75. Related to the pgsql-bugs thread for BUG #19903, where a patch has been proposed. The same elog is reached for property graphs via a different branch (BUG #19559).