mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
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.
This commit is contained in:
@ -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",
|
||||
@ -1711,6 +1711,17 @@ renamerel(Oid myrelid, const char *newrelname, ObjectType reltype)
|
||||
if (OidIsValid(targetrelation->rd_rel->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!
|
||||
*/
|
||||
|
Reference in New Issue
Block a user