has_any_column_privilege()

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

has_any_column_privilege() is a system function determining whether a user has a privilege for one or more columns of a table.

has_any_column_privilege() was added in PostgreSQL 8.4.

Usage

has_any_column_privilege() has two forms:

  • has_any_column_privilege(table TEXT or OID, privilege TEXT)
  • has_any_column_privilege(user TEXT or OID, table TEXT or OID, privilege TEXT)

The following privileges can be queried:

  • SELECT
  • INSERT
  • UPDATE
  • REFERENCES

Note that when providing the table name as an OID, the function will return NULL if no matching object is found. If the name is provided as a string, an error will be raised if no matching object is found.

Change history

Examples

Determine if the current user has the SELECT privilege for any column in the specified table:

postgres=# SELECT has_any_column_privilege('foo', 'SELECT');
 has_any_column_privilege 
--------------------------
 t
(1 row)

Determine if the specified user has the UPDATE privilege for any column in the specified table:

postgres=# SELECT has_any_column_privilege('someuser', 'foo', 'UPDATE');
 has_any_column_privilege 
--------------------------
 f
(1 row)

Attempting to determine an unrecognized privilege for this object type:

postgres=# SELECT has_any_column_privilege('foo', 'USAGE');
ERROR:  unrecognized privilege type: "USAGE"

Attempting to determine privileges for a non-existent table:

postgres=# SELECT has_any_column_privilege('bar', 'REFERENCES');
ERROR:  relation "bar" does not exist

Attempting to determine privileges for a non-existent OID:

postgres=# SELECT has_any_column_privilege(9999, 'SELECT');
 has_any_column_privilege
--------------------------

(1 row)

Categories

System function, User management

See also

has_column_privilege()