to_regrole()

A function translating a role name to an OID

to_regrole() is a system function for translating the name of a role (user or group) to its OID.

to_regrole() was added in PostgreSQL 9.5.

Usage

to_regrole ( text ) → regrole

to_regrole() is equivalent to using the regrole object identifier type cast, but returns NULL rather than raising an ERROR if no matching role is found.

Change history

Examples

Basic usage example for to_regrole():

postgres=# SELECT to_regrole('postgres')::oid;
 to_regrole 
------------
         10
(1 row)

NULL is returned if the specified role does not exist:

postgres=# SELECT to_regrole('foo') IS NULL;
 ?column? 
----------
 t
(1 row)

Categories

System function, Users and roles

See also

regrole