Skip to content

Commit 8178d94

Browse files
committed
Throw an appropriate error if ALTER COLUMN TYPE finds a dependent trigger.
Actually making this case work, if the column is used in the trigger's WHEN condition, will take some new code that probably isn't appropriate to back-patch. For now, just throw a FEATURE_NOT_SUPPORTED error rather than allowing control to reach the "unexpected object" case. Per bug #5688 from Daniel Grace. Back-patch to 9.0 where the possibility of such a dependency was introduced.
1 parent a0ccae7 commit 8178d94

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/backend/commands/tablecmds.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6148,6 +6148,24 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
61486148
colName)));
61496149
break;
61506150

6151+
case OCLASS_TRIGGER:
6152+
/*
6153+
* A trigger can depend on a column because the column is
6154+
* specified as an update target, or because the column is
6155+
* used in the trigger's WHEN condition. The first case would
6156+
* not require any extra work, but the second case would
6157+
* require updating the WHEN expression, which will take a
6158+
* significant amount of new code. Since we can't easily tell
6159+
* which case applies, we punt for both. FIXME someday.
6160+
*/
6161+
ereport(ERROR,
6162+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6163+
errmsg("cannot alter type of a column used in a trigger definition"),
6164+
errdetail("%s depends on column \"%s\"",
6165+
getObjectDescription(&foundObject),
6166+
colName)));
6167+
break;
6168+
61516169
case OCLASS_DEFAULT:
61526170

61536171
/*
@@ -6168,7 +6186,6 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
61686186
case OCLASS_OPFAMILY:
61696187
case OCLASS_AMOP:
61706188
case OCLASS_AMPROC:
6171-
case OCLASS_TRIGGER:
61726189
case OCLASS_SCHEMA:
61736190
case OCLASS_TSPARSER:
61746191
case OCLASS_TSDICT:

0 commit comments

Comments
 (0)