Contents
has_any_column_privilege()
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 ( [user
name
oroid
, ]table
text
oroid
,privilege
text
) →boolean
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
- PostgreSQL 8.4
- added (commit 7449427a)
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)
References
- PostgreSQL documentation: Access Privilege Inquiry Functions