has_server_privilege()

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

has_server_privilege() is a system function determining whether a user has the specified privilege for the specified foreign server.

has_server_privilege() was added in PostgreSQL 8.4.

Usage

has_server_privilege(server text or oid, privilege text)
has_server_privilege(user text or oid, server text or oid, privilege text)

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

Change history

Examples

The following examples assume a FDW set up as follows:

postgres=# \des
         List of foreign servers
  Name  |  Owner   | Foreign-data wrapper 
--------+----------+----------------------
 pg_fdw | postgres | postgres_fdw
(1 row)

Determine if the current user has the USAGE privilege for the specified foreign server:

postgres=# SELECT has_server_privilege('pg_fdw', 'USAGE');
 has_server_privilege 
----------------------
 t
(1 row)

Determine if the specified user has the USAGE privilege for the specified foreign server:

postgres=# SELECT has_server_privilege('foo', 'pg_fdw', 'USAGE');
 has_server_privilege 
----------------------
 f
(1 row)

Attempting to determine an unrecognized privilege for this object type:

postgres=# SELECT has_server_privilege('pg_fdw', 'UPDATE');
ERROR:  unrecognized privilege type: "UPDATE"

Attempting to determine privileges for a non-existent foreign server:

postgres=# SELECT has_server_privilege('microfiche_archive_2nd_floor', 'USAGE');
ERROR:  server "microfiche_archive_2nd_floor" does not exist

Categories

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

See also

has_foreign_data_wrapper_privilege()