diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-06-25 21:55:59 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-06-25 21:55:59 +0000 |
commit | 0adfa2c39d567394f423c69bfaf467d0d00ee3df (patch) | |
tree | 215559f976b4e28454fcf7abaa8c96c748ec7fef /src/backend/commands/conversioncmds.c | |
parent | 1621192b11369a7f0c47aaff1c8ec16bad29ab69 (diff) | |
download | postgresql-0adfa2c39d567394f423c69bfaf467d0d00ee3df.tar.gz postgresql-0adfa2c39d567394f423c69bfaf467d0d00ee3df.zip |
Support renaming of tablespaces, and changing the owners of
aggregates, conversions, functions, operators, operator classes,
schemas, types, and tablespaces. Fold the existing implementations
of alter domain owner and alter database owner in with these.
Christopher Kings-Lynne
Diffstat (limited to 'src/backend/commands/conversioncmds.c')
-rw-r--r-- | src/backend/commands/conversioncmds.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c index 1e55398f86e..298085f160b 100644 --- a/src/backend/commands/conversioncmds.c +++ b/src/backend/commands/conversioncmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.12 2003/11/29 19:51:47 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.13 2004/06/25 21:55:53 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -171,3 +171,55 @@ RenameConversion(List *name, const char *newname) heap_close(rel, NoLock); heap_freetuple(tup); } + +/* + * Change conversion owner + */ +void +AlterConversionOwner(List *name, AclId newOwnerSysId) +{ + Oid conversionOid; + HeapTuple tup; + Relation rel; + Form_pg_conversion convForm; + + rel = heap_openr(ConversionRelationName, RowExclusiveLock); + + conversionOid = FindConversionByName(name); + if (!OidIsValid(conversionOid)) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("conversion \"%s\" does not exist", + NameListToString(name)))); + + tup = SearchSysCacheCopy(CONOID, + ObjectIdGetDatum(conversionOid), + 0, 0, 0); + if (!HeapTupleIsValid(tup)) /* should not happen */ + elog(ERROR, "cache lookup failed for conversion %u", conversionOid); + + convForm = (Form_pg_conversion) GETSTRUCT(tup); + + /* + * If the new owner is the same as the existing owner, consider the + * command to have succeeded. This is for dump restoration purposes. + */ + if (convForm->conowner != newOwnerSysId) + { + /* Otherwise, must be superuser to change object ownership */ + if (!superuser()) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + errmsg("must be superuser to change owner"))); + + /* Modify the owner --- okay to scribble on tup because it's a copy */ + convForm->conowner = newOwnerSysId; + + simple_heap_update(rel, &tup->t_self, tup); + + CatalogUpdateIndexes(rel, tup); + } + + heap_close(rel, NoLock); + heap_freetuple(tup); +} |