diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-01-17 18:56:54 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-01-17 18:56:54 +0000 |
commit | 0df7717faa92ffc9d722495e2904767993b19d86 (patch) | |
tree | a9d2111ef0890a9bdbc5c4612188c35efec6445a /src/backend/commands/tablecmds.c | |
parent | d07de6c4ecdd5ba3340e94c99957fa899736c53b (diff) |
Fix ALTER INDEX RENAME so that if the index belongs to a unique or primary key
constraint, the constraint is renamed as well. This avoids inconsistent
situations that could confuse pg_dump (not to mention humans). We might at
some point provide ALTER TABLE RENAME CONSTRAINT as a more general solution,
but there seems no reason not to allow doing it this way too. Per bug #3854
and related discussions.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 301420c401d..571990eef9b 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.239 2008/01/02 23:34:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.240 2008/01/17 18:56:54 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1659,13 +1659,13 @@ renamerel(Oid myrelid, const char *newrelname, ObjectType reltype) * or ALTER INDEX is used to rename a sequence or view. */ relkind = targetrelation->rd_rel->relkind; - if (reltype == OBJECT_SEQUENCE && relkind != 'S') + if (reltype == OBJECT_SEQUENCE && relkind != RELKIND_SEQUENCE) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a sequence", RelationGetRelationName(targetrelation)))); - if (reltype == OBJECT_VIEW && relkind != 'v') + if (reltype == OBJECT_VIEW && relkind != RELKIND_VIEW) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a view", @@ -1712,6 +1712,17 @@ renamerel(Oid myrelid, const char *newrelname, ObjectType reltype) TypeRename(targetrelation->rd_rel->reltype, newrelname, namespaceId); /* + * Also rename the associated constraint, if any. + */ + if (relkind == RELKIND_INDEX) + { + Oid constraintId = get_index_constraint(myrelid); + + if (OidIsValid(constraintId)) + RenameConstraintById(constraintId, newrelname); + } + + /* * Close rel, but keep exclusive lock! */ relation_close(targetrelation, NoLock); |