Skip to content

Commit acdd6ea

Browse files
committed
Forbid renaming columns of objects whose column names are system-generated.
KaiGai Kohei, with adjustments to the comments.
1 parent a836abe commit acdd6ea

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/backend/commands/tablecmds.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.328 2010/03/10 19:48:39 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.329 2010/03/20 00:43:42 rhaas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1943,6 +1943,7 @@ renameatt(Oid myrelid,
19431943
HeapTuple atttup;
19441944
Form_pg_attribute attform;
19451945
int attnum;
1946+
char relkind;
19461947

19471948
/*
19481949
* Grab an exclusive lock on the target table, which we will NOT release
@@ -1955,6 +1956,23 @@ renameatt(Oid myrelid,
19551956
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
19561957
errmsg("cannot rename column of typed table")));
19571958

1959+
/*
1960+
* Renaming the columns of sequences or toast tables doesn't actually
1961+
* break anything from the system's point of view, since internal
1962+
* references are by attnum. But it doesn't seem right to allow users
1963+
* to change names that are hardcoded into the system, hence the following
1964+
* restriction.
1965+
*/
1966+
relkind = RelationGetForm(targetrelation)->relkind;
1967+
if (relkind != RELKIND_RELATION &&
1968+
relkind != RELKIND_VIEW &&
1969+
relkind != RELKIND_COMPOSITE_TYPE &&
1970+
relkind != RELKIND_INDEX)
1971+
ereport(ERROR,
1972+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1973+
errmsg("\"%s\" is not a table, view, composite type or index",
1974+
RelationGetRelationName(targetrelation))));
1975+
19581976
/*
19591977
* permissions checking. only the owner of a class can change its schema.
19601978
*/

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