Re: BUG #18449: Altering column type fails when an SQL routine depends on the column

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: exclusion(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Subject: Re: BUG #18449: Altering column type fails when an SQL routine depends on the column
Date: 2024-04-28 01:48:21
Message-ID: 403599.1714268901@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> The following script:
> CREATE TABLE t(a int, b varchar);
> CREATE FUNCTION f(i int) RETURNS text LANGUAGE SQL
> RETURN (SELECT b FROM t WHERE a = $1);

> ALTER TABLE t ALTER COLUMN b TYPE text;
> fails with:
> ERROR: unexpected object depending on column: function f(integer)

> on REL_14_STABLE .. master since e717a9a18.

Thanks for the report. It looks like most of the other hard cases
in RememberAllDependentForRebuilding just error out with code
along the lines of

ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot alter type of a column used by a view or rule"),

I'm inclined to do likewise for functions. We could imagine trying
to re-parse the function definition against the new column type,
but there are way too many ways for that to go wrong. Just for
starters, there are possibly-security-grade hazards if the current
search_path isn't what it was when the function was created. There's
no guarantee that we'd succeed anyway, eg the new column type might
not work for some function or operator that's applied to it, and if
not the resulting error message would likely be very surprising.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2024-04-29 00:54:07 Re: BUG #17855: Uninitialised memory used when the name type value processed in binary mode of Memoize
Previous Message 周志勤 2024-04-28 01:03:01 edb installation failed for pgadmin when username is Chinese under c;\user #7432