Overview

The pg_get_userbyid() is a system catalog information function that retrieves that name of a user (role) given its unique identifier (OID).

Syntax

The syntax for the pg_get_userbyid() function is as follows:

pg_get_userbyid(role_oid)

Parameters

The following parameters are required to execute this function:

  • role_oid: specifies the object identifier (OIDs) of the users

Example

In this example, what we will do first is to get the OIDs of all the users

SELECT id,name FROM oxla_internal.oxla_role;

Then, return the list of users with their ids (OIDs):

 id |  name
----+---------
  1 | oxla
  2 | other_user
(2 rows)

As the next step we will translate the OID to a role name in a following way:

SELECT pg_get_userbyid(2);

By executing the code above, we will get the following result:

 pg_get_userbyid
-----------------
 other_user
(1 row)