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:

  • BACKUP
  • CONNECT
  • CREATE
  • EXPLAIN QUERY
  • RESTORE
  • TEMP
  • 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)

Parent topic:System Functions