mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Refactor ALTER some-obj RENAME implementation
Remove duplicate implementations of catalog munging and miscellaneous privilege checks. Instead rely on already existing data in objectaddress.c to do the work. Author: KaiGai Kohei, changes by me Reviewed by: Robert Haas, Álvaro Herrera, Dimitri Fontaine
This commit is contained in:
@ -536,48 +536,6 @@ DropProceduralLanguageById(Oid langOid)
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Rename language
|
||||
*/
|
||||
Oid
|
||||
RenameLanguage(const char *oldname, const char *newname)
|
||||
{
|
||||
Oid lanId;
|
||||
HeapTuple tup;
|
||||
Relation rel;
|
||||
|
||||
rel = heap_open(LanguageRelationId, RowExclusiveLock);
|
||||
|
||||
tup = SearchSysCacheCopy1(LANGNAME, CStringGetDatum(oldname));
|
||||
if (!HeapTupleIsValid(tup))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("language \"%s\" does not exist", oldname)));
|
||||
|
||||
lanId = HeapTupleGetOid(tup);
|
||||
|
||||
/* make sure the new name doesn't exist */
|
||||
if (SearchSysCacheExists1(LANGNAME, CStringGetDatum(newname)))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
||||
errmsg("language \"%s\" already exists", newname)));
|
||||
|
||||
/* must be owner of PL */
|
||||
if (!pg_language_ownercheck(HeapTupleGetOid(tup), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE,
|
||||
oldname);
|
||||
|
||||
/* rename */
|
||||
namestrcpy(&(((Form_pg_language) GETSTRUCT(tup))->lanname), newname);
|
||||
simple_heap_update(rel, &tup->t_self, tup);
|
||||
CatalogUpdateIndexes(rel, tup);
|
||||
|
||||
heap_close(rel, NoLock);
|
||||
heap_freetuple(tup);
|
||||
|
||||
return lanId;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_language_oid - given a language name, look up the OID
|
||||
*
|
||||
|
Reference in New Issue
Block a user