pg_get_userbyid()

A function returning a role's name from its OID

pg_get_userbyid() is a system function for retrieiving a role (user) name from its OID.

pg_get_userbyid() was added in PostgreSQL 6.4.

Usage

pg_get_userbyid ( role oid ) → name

pg_get_userbyid() is mainly used in queries over system catalog relations.

If no role matches the specified OID, the string "unknown (OID=oid)" is returned.

Change history

Examples

Basic usage example for pg_get_userbyid():

postgres=# SELECT pg_get_userbyid(10);
 pg_get_userbyid 
-----------------
 postgres
(1 row)

Attempting to retrieve the role name for a non-existent role:

postgres=# SELECT pg_get_userbyid(999);
  pg_get_userbyid  
-------------------
 unknown (OID=999)
(1 row)

Providing an invalid OID:

postgres=# SELECT pg_get_userbyid(4294967296);
ERROR:  OID out of range

Categories

System catalogue, System function, User management

See also

pg_has_role(), pg_authid