| From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
|---|---|
| To: | hackerzheng666(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19903: ALTER COLUMN TYPE: "unexpected object depending on column" internal error via partition key |
| Date: | 2026-11-16 20:11:04 |
| Message-ID: | CA+TgmoZFt-8k0yf695y0FQC48eHEN2_bYDSTN5e8SX-MRv7z=g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
On Mon, Nov 16, 2026 at 10:55 AM PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:
> ALTER COLUMN TYPE on a column of a table that is also used as a composite
> type raises an internal (XX000) error if the partition key expression of
> another table selects a field of that composite type:
>
> 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: unexpected object depending on column: table atref
Yeah, that's not great. Here's what my LLM thinks:
RememberAllDependentForRebuilding() expects the only relations that
depend directly on a column to be indexes and sequences. A partition
key can depend on one too, because selecting a field from a composite
value records a dependency on that column. That's been so since 2017,
so all supported branches have this.
Just ignoring partitioned tables there won't do, though. In the
reporter's example the rowtype check that produces the index and CHECK
messages runs later and would still reject the ALTER. But a key that
gets at the field through a function result doesn't use the rowtype at
all:
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;
With partitioned tables skipped, that ALTER succeeds, and afterwards an
INSERT into atref from a new session fails with "attribute 1 has wrong
type". We can't rebuild a partition key, so the column dependency is
all that stands in the way, and the error belongs here.
The attached reports "cannot alter type of a column used in a partition
key expression", with a detail naming the partitioned table. I prefer
that to the "uses its row type" wording suggested in the report because
it's also accurate for the function case. As 42b041243c (Tom Lane,
2024-04-28) did for SQL function bodies, it lets ALTER COLUMN SET
EXPRESSION through, since that can't change the column's type.
Since this only changes cases that fail today, I think it should go
back to 14. Branches before 17 have no SET EXPRESSION, so that part
drops out there.
--
Robert Haas
Databricks
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Throw-a-more-on-point-error-for-partition-keys-depen.patch | application/octet-stream | 6.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2026-11-16 20:16:46 | Re: BUG #19908: pg_upgrade --check crashes instance if running in a different PID Namespace then the old cluster |
| Previous Message | Robert Haas | 2026-11-16 19:44:21 | Re: BUG #19899: PL/Python backend crashes (SIGSEGV) when converting a column value to a Python object fails |