Re: alter user/role CURRENT_USER - Mailing list pgsql-hackers

From Kyotaro HORIGUCHI
Subject Re: alter user/role CURRENT_USER
Date
Msg-id 20141021.160643.138996639.horiguchi.kyotaro@lab.ntt.co.jp
Whole thread Raw
In response to Re: alter user/role CURRENT_USER  ("Brightwell, Adam" <adam.brightwell@crunchydatasolutions.com>)
Responses Re: alter user/role CURRENT_USER
List pgsql-hackers
Hello,

> Kyotaro,
> 
> Food for thought.  Couldn't you reduce the following block:
> 
> + if (strcmp(stmt->role, "current_user") == 0)
> + {
> + roleid = GetUserId();
> + tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
> + if (!HeapTupleIsValid(tuple))
> + ereport(ERROR,
> + (errcode(ERRCODE_UNDEFINED_OBJECT),
> + errmsg("roleid %d does not exist", roleid)));
> + }
> + else
> + {
> + tuple = SearchSysCache1(AUTHNAME, PointerGetDatum(stmt->role));
> + if (!HeapTupleIsValid(tuple))
> + ereport(ERROR,
> + (errcode(ERRCODE_UNDEFINED_OBJECT),
> + errmsg("role \"%s\" does not exist", stmt->role)));
> 
> To:
> 
> if (strcmp(stmt->role, "current_user") == 0)
> roleid = GetUserId();
> else
> roleid = get_role_oid(stmt->role, false);
> 
> tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
> 
> if (!HeapTupleIsValid(tuple))
> ereport(ERROR,
> (errcode(ERRCODE_UNDEFINED_OBJECT),
>  errmsg("roleid %d does not exist", roleid)));
> 
> I think this makes it a bit cleaner.  It also reuses existing code as
> 'get_role_oid()' already does a valid role name check and will raise the
> proper error.

Year, far cleaner. I missed the function. Thank you.

regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center




pgsql-hackers by date:

Previous
From: Kyotaro HORIGUCHI
Date:
Subject: Re: alter user/role CURRENT_USER
Next
From: Amit Kapila
Date:
Subject: Re: Wait free LW_SHARED acquisition - v0.9