has_function_privilege()

A system function determining whether a user has a privilege for a function

has_function_privilege() is a system function determining whether a user has the specified privilege for the specified function.

has_function_privilege() was added in PostgreSQL 7.3.

Usage

has_function_privilege() has two forms:

  • has_function_privilege(function TEXT or OID, privilege TEXT)
  • has_function_privilege(user TEXT or OID, function TEXT or OID, privilege TEXT)

The only privilege which can be queried with has_function_privilege() is: EXECUTE.

Change history

Examples

Determine if the current user has the EXECUTE privilege for the specified function:

postgres=# SELECT has_function_privilege(pg_is_in_recovery()', 'EXECUTE');
 has_function_privilege 
------------------------
 t
(1 row)

The function must be specified as function(...), otherwise an error will be raised:

postgres=# SELECT has_function_privilege('pg_is_in_recovery', 'EXECUTE');
ERROR:  expected a left parenthesis

Determine if the specified user has the EXECUTE privilege for the specified function:

postgres=# SELECT has_function_privilege('someuser', 'pg_read_file(text)', 'EXECUTE');
 has_function_privilege 
------------------------
 f
(1 row)

Attempting to determine an unrecognized privilege for this object type:

postgres=# SELECT has_function_privilege('pg_is_in_recovery()', 'CREATE');
ERROR:  unrecognized privilege type: "CREATE"

Attempting to determine privileges for a non-existent function:

postgres=# SELECT has_function_privilege('somefunction()', 'EXECUTE');
ERROR:  function "somefunction()" does not exist

Categories

Functions and procedures, System function, User management