Re: BUG #18449: Altering column type fails when an SQL routine depends on the column
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org,
Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Date: 2024-04-28T01:48:21Z
Lists: pgsql-bugs
PG Bug reporting form <noreply@postgresql.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
Commits
-
Throw a more on-point error for publications depending on columns.
- 91e7115b177b 17.0 landed
- 5f4a1a0a7758 15.7 landed
- 11d40a44ba32 16.3 landed
-
Throw a more on-point error for functions depending on columns.
- b19255ca66f7 16.3 landed
- 9b41d1d634aa 15.7 landed
- 617a23927249 14.12 landed
- 42b041243c00 17.0 landed