Skip to main content

GRANT

Use the GRANT command to give a user specific privileges.

Syntax

Grant a user database privileges.

GRANT {{CONNECT | CREATE}[, ...]| ALL [PRIVILEGES]} 
ON DATABASE database_name [, ...]
TO user_name [WITH GRANT OPTION] [GRANTED BY user_name];

Grant a user materialized view privileges.

GRANT {SELECT | ALL [PRIVILEGES]} 
ON {MATERIALIZED VIEW mv_name [, ...]
| ALL MATERIALIZED VIEWS IN SCHEMA schema_name [, ...] }
TO user_name [WITH GRANT OPTION] [GRANTED BY user_name];

Grant a user schema privileges.

GRANT {CREATE | ALL [PRIVILEGES]} 
ON SCHEMA schema_name [, ...]
TO user_name [WITH GRANT OPTION] [GRANTED BY user_name];

Grant a user source privileges.

GRANT {{SELECT | UPDATE | INSERT | DELETE} [, ...]| ALL [PRIVILEGES]} 
ON {SOURCE source_name [, ...]
| ALL SOURCES IN SCHEMA schema_name [, ...] }
TO user_name [WITH GRANT OPTION] [GRANTED BY user_name];

Parameters

Parameter or clauseDescription
database_nameThe database the user will be granted privilege to.
mv_nameThe materialized view the user will be granted privilege to.
schema_nameThe schema the user will be granted privilege to.
source_nameThe data source the user will be granted privilege to.
user_nameA Postgres user.
WITH GRANT OPTION clauseThe WITH GRANT OPTION clause allows the grantee to grant the privilege to other users.
GRANTED BY clauseThe specified user after the GRANTED BY clause must be the current user. By default, the current user is root.

Example

Grant all privileges for all sources in schema1 to user user1.

GRANT ALL PRIVILEGES 
ON ALL SOURCES IN SCHEMA schema1
TO user1 GRANTED BY user;

Grant the SELECT privilege for materialized view mv1, which is in schema schema1 of database db1, to user user1. user1 is able to grant the SELECT privilege other users.

GRANT SELECT
ON MATERIALIZED VIEW mv1 IN SCHEMA db1.schema1
TO user1 WITH GRANT OPTION GRANTED BY user;

Grant the SELECT and UPDATE privileges for source s1 to user user1.

GRANT SELECT, UPDATE
ON SOURCE s1
TO user1;

Help us make this doc better!