View Privileges
A view is a stored query that dynamically accesses and computes data from the database at execution time. Use \dv in vsql to display available views. By default, only the following users have privileges to access a view's base object:
- Superuser
- View owner—typically, the view creator
To execute a query that contains a view, you must have:
- SELECT privileges assigned with GRANT (View)
- USAGE privileges on the view's schema, assigned with GRANT (Schema).
You can assign view privileges to other users and roles using GRANT (View). For example:
- Assign
GRANT ALL
privileges to a user or role.
=> GRANT all privileges on view1 to role1 with grant option;
- Assign
GRANT ROLE
privileges to a specific role to provide view privileges. In the following example, privileges that are assigned torole1
are assigned torole2
:
=> CREATE ROLE role1;
=> CREATE ROLE role2;
=> GRANT role1 to role2;