HAS_TABLE_PRIVILEGE
Indicates whether a user can access a table in a particular way. The function returns a true (t
) or false (f
) value.
Behavior Type
Syntax
HAS_TABLE_PRIVILEGE ( [ user, ] [[database.]schema.]table, privilege )
Parameters
user
|
Specifies the name or OID of a database user. The default is the CURRENT_USER. |
[database.]schema
|
Specifies a schema, by default myschema.thisDbObject If you specify a database, it must be the current database. |
table
|
Specifies the name or OID of a table in the logical schema. If necessary, specify the database and schema, as noted above. |
privilege
|
|
Privileges
A superuser can check all other user's table privileges.
Users without superuser privileges can use HAS_TABLE_PRIVILEGE to check:
- Any tables they own.
- Tables in a schema to which they have been granted USAGE privileges, and at least one other table privilege, as described in GRANT (Table).
Examples
=> SELECT HAS_TABLE_PRIVILEGE('store.store_dimension', 'SELECT'); HAS_TABLE_PRIVILEGE --------------------- t (1 row)
=> SELECT HAS_TABLE_PRIVILEGE('release', 'store.store_dimension', 'INSERT'); HAS_TABLE_PRIVILEGE --------------------- t (1 row)
=> SELECT HAS_TABLE_PRIVILEGE('store.store_dimension', 'UPDATE'); HAS_TABLE_PRIVILEGE --------------------- t (1 row)
=> SELECT HAS_TABLE_PRIVILEGE('store.store_dimension', 'REFERENCES'); HAS_TABLE_PRIVILEGE --------------------- t (1 row) => SELECT HAS_TABLE_PRIVILEGE(45035996273711159, 45035996273711160, 'select'); HAS_TABLE_PRIVILEGE --------------------- t
(1 row)