Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit42b0412

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 objectsdepending on the column whose type is to be altered. That indeedwasn't possible when this code was written, but it is possiblesince we introduced new-style SQL function bodies.It's about as difficult to fix this case as it is to fix dependentviews, and we've been punting on those for years, so I don't feeltoo awful about punting for functions too. (I sure wouldn't riskback-patching such code.) So just throw a more user-facing error.Also, adjust some of the existing comments to reflect that theseare all pretty much the same issue.(This patch also fixes it so we will tolerate finding such adependency during ALTER COLUMN SET EXPRESSION; in that, we neednot do anything to the function, so no error is wanted. Thatproblem is new in HEAD.)Per bug #18449 from Alexander Lakhin. Back-patch to v14 wherewe added new-style SQL functions.Discussion:https://postgr.es/m/18449-f8248467aaa294d5@postgresql.org
1 parent4019285 commit42b0412

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "catalog/pg_namespace.h"
4646
#include "catalog/pg_opclass.h"
4747
#include "catalog/pg_policy.h"
48+
#include "catalog/pg_proc.h"
4849
#include "catalog/pg_rewrite.h"
4950
#include "catalog/pg_statistic_ext.h"
5051
#include "catalog/pg_tablespace.h"
@@ -14094,8 +14095,33 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype,
1409414095
RememberConstraintForRebuilding(foundObject.objectId, tab);
1409514096
break;
1409614097

14098+
case ProcedureRelationId:
14099+
14100+
/*
14101+
* A new-style SQL function can depend on a column, if that
14102+
* column is referenced in the parsed function body. Ideally
14103+
* we'd automatically update the function by deparsing and
14104+
* reparsing it, but that's risky and might well fail anyhow.
14105+
* FIXME someday.
14106+
*
14107+
* This is only a problem for AT_AlterColumnType, not
14108+
* AT_SetExpression.
14109+
*/
14110+
if (subtype == AT_AlterColumnType)
14111+
ereport(ERROR,
14112+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14113+
errmsg("cannot alter type of a column used by a function or procedure"),
14114+
errdetail("%s depends on column \"%s\"",
14115+
getObjectDescription(&foundObject, false),
14116+
colName)));
14117+
break;
14118+
1409714119
case RewriteRelationId:
14098-
/* XXX someday see if we can cope with revising views */
14120+
14121+
/*
14122+
* View/rule bodies have pretty much the same issues as
14123+
* function bodies. FIXME someday.
14124+
*/
1409914125
if (subtype == AT_AlterColumnType)
1410014126
ereport(ERROR,
1410114127
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -14112,9 +14138,9 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype,
1411214138
* specified as an update target, or because the column is
1411314139
* used in the trigger's WHEN condition. The first case would
1411414140
* not require any extra work, but the second case would
14115-
* require updating the WHEN expression, whichwill take a
14116-
*significant amount of new code. Since we can't easily tell
14117-
*which caseapplies, we punt for both. FIXME someday.
14141+
* require updating the WHEN expression, whichhas the same
14142+
*issues as above. Since we can't easily tell which case
14143+
* applies, we punt for both. FIXME someday.
1411814144
*/
1411914145
if (subtype == AT_AlterColumnType)
1412014146
ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp