pg_has_role()

A function determining whether a user is a member of a particular role

pg_has_role() is a system function determining whether a database user is a member of a particular role (group).

pg_has_role() was added in PostgreSQL 8.1.

Usage

pg_has_role ( [ user NAME or OID, ] role TEXT or OID, privilege TEXT ) → BOOLEAN

The privilege type can be one of MEMBER or USAGE.

Change history

Examples

Basic execution example for pg_has_role():

postgres=# SELECT pg_has_role('pg_read_all_settings', 'MEMBER');
 pg_has_role 
-------------
 t
(1 row)

Attempting to query a non-existent role:

postgres=# SELECT pg_has_role('foo', 'MEMBER');
ERROR:  role "foo" does not exist

Attempting to query an unknown privilege type:

postgres=# SELECT pg_has_role('pg_read_all_settings', 'FOO');
ERROR:  unrecognized privilege type: "FOO"

Categories

System function, User management

See also

pg_auth_members