Skip to content

Commit 1f0b62e

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 50595b5 commit 1f0b62e

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
@@ -6411,6 +6411,24 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
64116411
colName)));
64126412
break;
64136413

6414+
case OCLASS_TRIGGER:
6415+
/*
6416+
* A trigger can depend on a column because the column is
6417+
* specified as an update target, or because the column is
6418+
* used in the trigger's WHEN condition. The first case would
6419+
* not require any extra work, but the second case would
6420+
* require updating the WHEN expression, which will take a
6421+
* significant amount of new code. Since we can't easily tell
6422+
* which case applies, we punt for both. FIXME someday.
6423+
*/
6424+
ereport(ERROR,
6425+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6426+
errmsg("cannot alter type of a column used in a trigger definition"),
6427+
errdetail("%s depends on column \"%s\"",
6428+
getObjectDescription(&foundObject),
6429+
colName)));
6430+
break;
6431+
64146432
case OCLASS_DEFAULT:
64156433

64166434
/*
@@ -6431,7 +6449,6 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
64316449
case OCLASS_OPFAMILY:
64326450
case OCLASS_AMOP:
64336451
case OCLASS_AMPROC:
6434-
case OCLASS_TRIGGER:
64356452
case OCLASS_SCHEMA:
64366453
case OCLASS_TSPARSER:
64376454
case OCLASS_TSDICT:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy