Skip to content

Commit 617a239

Browse files
committed
Throw a more on-point error for functions depending on columns.
ALTER COLUMN TYPE wasn't expecting to find any pg_proc objects depending on the column whose type is to be altered. That indeed wasn't possible when this code was written, but it is possible since we introduced new-style SQL function bodies. It's about as difficult to fix this case as it is to fix dependent views, and we've been punting on those for years, so I don't feel too awful about punting for functions too. (I sure wouldn't risk back-patching such code.) So just throw a more user-facing error. Also, adjust some of the existing comments to reflect that these are all pretty much the same issue. (This patch also fixes it so we will tolerate finding such a dependency during ALTER COLUMN SET EXPRESSION; in that, we need not do anything to the function, so no error is wanted. That problem is new in HEAD.) Per bug #18449 from Alexander Lakhin. Back-patch to v14 where we added new-style SQL functions. Discussion: https://postgr.es/m/18449-f8248467aaa294d5@postgresql.org
1 parent 1748379 commit 617a239

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/backend/commands/tablecmds.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12231,8 +12231,29 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
1223112231
RememberConstraintForRebuilding(foundObject.objectId, tab);
1223212232
break;
1223312233

12234+
case OCLASS_PROC:
12235+
12236+
/*
12237+
* A new-style SQL function can depend on a column, if that
12238+
* column is referenced in the parsed function body. Ideally
12239+
* we'd automatically update the function by deparsing and
12240+
* reparsing it, but that's risky and might well fail anyhow.
12241+
* FIXME someday.
12242+
*/
12243+
ereport(ERROR,
12244+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12245+
errmsg("cannot alter type of a column used by a function or procedure"),
12246+
errdetail("%s depends on column \"%s\"",
12247+
getObjectDescription(&foundObject, false),
12248+
colName)));
12249+
break;
12250+
1223412251
case OCLASS_REWRITE:
12235-
/* XXX someday see if we can cope with revising views */
12252+
12253+
/*
12254+
* View/rule bodies have pretty much the same issues as
12255+
* function bodies. FIXME someday.
12256+
*/
1223612257
ereport(ERROR,
1223712258
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1223812259
errmsg("cannot alter type of a column used by a view or rule"),
@@ -12248,9 +12269,9 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
1224812269
* specified as an update target, or because the column is
1224912270
* used in the trigger's WHEN condition. The first case would
1225012271
* not require any extra work, but the second case would
12251-
* require updating the WHEN expression, which will take a
12252-
* significant amount of new code. Since we can't easily tell
12253-
* which case applies, we punt for both. FIXME someday.
12272+
* require updating the WHEN expression, which has the same
12273+
* issues as above. Since we can't easily tell which case
12274+
* applies, we punt for both. FIXME someday.
1225412275
*/
1225512276
ereport(ERROR,
1225612277
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -12296,7 +12317,6 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
1229612317
RememberStatisticsForRebuilding(foundObject.objectId, tab);
1229712318
break;
1229812319

12299-
case OCLASS_PROC:
1230012320
case OCLASS_TYPE:
1230112321
case OCLASS_CAST:
1230212322
case OCLASS_COLLATION:

0 commit comments

Comments
 (0)