select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / SYSTEM INFORMATION FUNCTIONS AND OPERATORS

Does user have privilege for role? Allowable privilege types are MEMBER, USAGE, and SET.

Signatures & examples

pg_has_role ( [ user name or oid, ] role text or oid, privilege text ) → boolean
Does user have privilege for role? Allowable privilege types are MEMBER, USAGE, and SET. MEMBER denotes direct or indirect membership in the role without regard to what specific privileges may be conferred. USAGE denotes whether the privileges of the role are immediately available without doing SET ROLE, while SET denotes whether it is possible to change to the role using the SET ROLE command. WITH ADMIN OPTION or WITH GRANT OPTION can be added to any of these privilege types to test whether the ADMIN privilege is held (all six spellings test the same thing). This function does not allow the special case of setting user to public, because the PUBLIC pseudo-role can never be a member of real roles.
Version history 2
  1. PG 15 → 16changed
  2. PG 12 → 13changed

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source