Skip to content

HAS_DATABASE_PRIVILEGE

Return true if the user has the specified privilege for the specified database.

HAS_DATABASE_PRIVILEGE([role,] database, privilege)

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

Valid privilege values are:

  • ALTER ANY SCHEMA
  • BACKUP
  • BULK LOAD
  • CONNECT
  • CONTROL
  • CREATE
  • DROP ANY SCHEMA
  • EXPLAIN QUERY
  • RESTORE
  • TEMP or TEMPORARY
  • 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_database_privilege('bobr','premdb','create');
 has_database_privilege 
------------------------
 f
(1 row)
premdb=# select has_database_privilege('premdb','create');
 has_database_privilege 
------------------------
 t
(1 row)

premdb=# select has_database_privilege('bobr','premdb','bulk load');
 has_database_privilege 
------------------------
 t
(1 row)