From 0c90f6769de6a60f842c916d49b404d03bcc503a Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Sat, 9 May 2015 13:06:49 -0400 Subject: Add new OID alias type regrole The new type has the scope of whole the database cluster so it doesn't behave the same as the existing OID alias types which have database scope, concerning object dependency. To avoid confusion constants of the new type are prohibited from appearing where dependencies are made involving it. Also, add a note to the docs about possible MVCC violation and optimization issues, which are general over the all reg* types. Kyotaro Horiguchi --- src/backend/utils/init/miscinit.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/backend/utils/init/miscinit.c') diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 1dc31535fd6..b0d85af14db 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -648,23 +648,29 @@ SetCurrentRoleId(Oid roleid, bool is_superuser) /* - * Get user name from user oid + * Get user name from user oid, returns NULL for nonexistent roleid if noerr + * is true. */ char * -GetUserNameFromId(Oid roleid) +GetUserNameFromId(Oid roleid, bool noerr) { HeapTuple tuple; char *result; tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid)); if (!HeapTupleIsValid(tuple)) - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_OBJECT), - errmsg("invalid role OID: %u", roleid))); - - result = pstrdup(NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname)); - - ReleaseSysCache(tuple); + { + if (!noerr) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("invalid role OID: %u", roleid))); + result = NULL; + } + else + { + result = pstrdup(NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname)); + ReleaseSysCache(tuple); + } return result; } -- cgit v1.2.3