has_foreign_data_wrapper_privilege()

A system function determining whether a user has a privilege for a foreign data wrapper

has_foreign_data_wrapper_privilege() is a system function determining whether a user has the specified privilege for the specified foreign data wrapper (FDW).

has_foreign_data_wrapper_privilege() was added in PostgreSQL 8.4.

Usage

has_foreign_data_wrapper_privilege() has two forms:

  • has_foreign_data_wrapper_privilege(fdw TEXT or OID, privilege TEXT)
  • has_foreign_data_wrapper_privilege(user TEXT or OID, fdw TEXT or OID, privilege TEXT)

The only privilege which can be queried with has_foreign_data_wrapper_privilege() is: USAGE.

Change history

Examples

The following examples assume a FDW installed as follows:

postgres=# \dew
                      List of foreign-data wrappers
     Name     |  Owner   |       Handler        |       Validator        
--------------+----------+----------------------+------------------------
 postgres_fdw | postgres | postgres_fdw_handler | postgres_fdw_validator
(1 row)

Determine if the current user has the USAGE privilege for the specified FDW:

postgres=# SELECT has_foreign_data_wrapper_privilege('postgres_fdw', 'USAGE');
 has_foreign_data_wrapper_privilege 
------------------------------------
 t
(1 row)

Determine if the specified user has the USAGE privilege for the specified FDW:

postgres=# SELECT has_foreign_data_wrapper_privilege('someuser', 'postgres_fdw', 'USAGE');
 has_foreign_data_wrapper_privilege 
------------------------------------
 f
(1 row)

Attempting to determine an unrecognized privilege for this object type:

postgres=# SELECT has_foreign_data_wrapper_privilege('postgres_fdw', 'DELETE');
ERROR:  unrecognized privilege type: "DELETE"

Attempting to determine privileges for a non-existent FDW:

postgres=# SELECT has_foreign_data_wrapper_privilege('hollerith_tabulator_fdw', 'USAGE');
ERROR:  foreign-data wrapper "hollerith_tabulator_fdw" does not exist

Categories

Foreign Data Wrapper (FDW), System function, User management

See also

has_server_privilege()