diff options
author | Robert Haas <rhaas@postgresql.org> | 2010-03-20 00:43:42 +0000 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2010-03-20 00:43:42 +0000 |
commit | acdd6ea5ab887fd18912578f110c55dab0f5ec97 (patch) | |
tree | af2f9aed11f922a0401b2a869b1e7b103da99dfb /src/backend/commands/tablecmds.c | |
parent | a836abe9f6934b51a0f92cb50c8514cd6f14c8b6 (diff) | |
download | postgresql-acdd6ea5ab887fd18912578f110c55dab0f5ec97.tar.gz postgresql-acdd6ea5ab887fd18912578f110c55dab0f5ec97.zip |
Forbid renaming columns of objects whose column names are system-generated.
KaiGai Kohei, with adjustments to the comments.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 79c5163e61b..dda0b2e847e 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.328 2010/03/10 19:48:39 rhaas Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.329 2010/03/20 00:43:42 rhaas Exp $ * *------------------------------------------------------------------------- */ @@ -1943,6 +1943,7 @@ renameatt(Oid myrelid, HeapTuple atttup; Form_pg_attribute attform; int attnum; + char relkind; /* * Grab an exclusive lock on the target table, which we will NOT release @@ -1956,6 +1957,23 @@ renameatt(Oid myrelid, errmsg("cannot rename column of typed table"))); /* + * Renaming the columns of sequences or toast tables doesn't actually + * break anything from the system's point of view, since internal + * references are by attnum. But it doesn't seem right to allow users + * to change names that are hardcoded into the system, hence the following + * restriction. + */ + relkind = RelationGetForm(targetrelation)->relkind; + if (relkind != RELKIND_RELATION && + relkind != RELKIND_VIEW && + relkind != RELKIND_COMPOSITE_TYPE && + relkind != RELKIND_INDEX) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not a table, view, composite type or index", + RelationGetRelationName(targetrelation)))); + + /* * permissions checking. only the owner of a class can change its schema. */ if (!pg_class_ownercheck(myrelid, GetUserId())) |