Skip to content

HAS_SYSTEM_PRIVILEGE

Return true if the user has the specified privilege on the system.

HAS_SYSTEM_PRIVILEGE([role,], privilege)

If the role name is omitted, the function returns results for the current user.

Valid privilege values are:

  • ALTER ANY DATABASE
  • ALTER ANY ROLE
  • BACKUP ANY DATABASE
  • CONTROL ANY SESSION
  • CONTROL LDAP
  • CREATE DATABASE
  • CREATE ROLE
  • DROP ANY DATABASE
  • DROP ANY ROLE
  • EXPLAIN QUERY
  • RESTORE ANY DATABASE
  • TRACE QUERY
  • VIEW QUERY TEXT

Note: This function cannot be used in a query that has a FROM clause (with table references).

For example:

premdb=# select has_system_privilege('bobr','restore any database');
 has_system_privilege 
----------------------
 f
(1 row)
premdb=# grant restore any database on system to bobr;
GRANT
premdb=# select has_system_privilege('bobr','restore any database');
 has_system_privilege 
----------------------
 t
(1 row)
premdb=# grant create database on system to yb100;
GRANT
premdb=# select has_system_privilege('yb100','create database');
 has_system_privilege 
----------------------
 t
(1 row)

Parent topic:System Functions