- Only users with the
user_adminrole can grant any privilege to other users and roles. - After a role is granted to a user, you must run SET ROLE to activate this role before you perform operations as this role. If you want all default roles to be activated upon login, run ALTER USER or SET DEFAULT ROLE. If you want all roles granted to each user to be activated upon login, set the global variable
SET GLOBAL activate_all_roles_on_login = TRUE;. - Common users can only grant privileges that have the
WITH GRANT OPTIONkeyword to other users and roles.
Syntax
Grant privileges to roles or users
System
AI functions and providers
USAGE ON ALL AI FUNCTIONS covers current and future families; with WITH GRANT OPTION, it permits delegating usage on named or all families. It does not include provider usage. Provider names retain their exact spelling. See AI privileges.
Resource group
Resource
Global UDF
GRANT usage ON GLOBAL FUNCTION a(string) to kevin;
Internal catalog
External catalog
Database
- You must first run SET CATALOG before you run this command.
- For databases in an External Catalog, you can grant the CREATE TABLE privilege only on Hive (since v3.1) and Iceberg databases (since v3.2).
Table
- You must first run SET CATALOG before you run this command.
-
You can also use
<db_name>.<table_name>to represent a table. -
You can grant the SELECT privilege on all tables in Internal and External Catalogs to read data from these tables. For tables in Hive and Iceberg Catalogs, you can grant the INSERT privilege to write data into such tables (supported since v3.1 for Iceberg and v3.2 for Hive)
View
- You must first run SET CATALOG before you run this command.
-
You can also use
<db_name>.<view_name>to represent a view. - For tables in an External Catalog, you can only grant the SELECT privilege on Hive table views (since v3.1).
-
For the EXPORT privilege, only grant and revoke are supported. Exporting the view via
EXPORT TABLEis not supported.
Materialized view
- You must first run SET CATALOG before you run this command.
-
You can also use
<db_name>.<mv_name>to represent an mv. -
For the EXPORT privilege, only grant and revoke are supported. Exporting the materialized view via
EXPORT TABLEis not supported.
ALL PRIVILEGES on views and materialized views now includes EXPORT. A user who was granted ALL ... WITH GRANT OPTION on a view or a materialized view before the upgrade and does not have the system-level GRANT privilege must be additionally granted EXPORT ... WITH GRANT OPTION by an administrator, otherwise they can no longer grant or revoke ALL PRIVILEGES on that object.
Function
- You must first run SET CATALOG before you run this command.
-
You can also use
<db_name>.<function_name>to represent a function.
User
Storage volume
Grant roles to roles, users, or external groups
Examples
Example 1: Grant the privilege to read data from all tables in all databases to userjack.
db1 to role my_role.
tbl1 of database db1 to user jack.
jack.
spark_resource to user jack.
spark_resource to role my_role.
sr_member to user jack and allow user jack to grant this privilege to other users or roles (by specifying WITH GRANT OPTION).
db_admin, user_admin, and cluster_admin to user user_platform.
jack to perform operations as user rose.
db_admin, user_admin, and cluster_admin to the external group admin_group.
Best practices
Customize roles based on scenarios
We recommend you customize roles to manage privileges and users. The following examples classify a few combinations of privileges for some common scenarios.
Grant global read-only privileges on tables
Grant global write privileges on tables
Grant read-only privileges on a specific external catalog
Grant write-only privileges on a specific external catalog
You can only write data into Iceberg tables (since v3.1) and Hive tables (since v3.2).Grant admin privileges on a specific database
Grant privileges to perform backup and restore operations on global, database, table, and partition levels
-
Grant privileges to perform global backup and restore operations:
The privileges to perform global backup and restore operations allow the role to back up and restore any database, table, or partition. It requires the REPOSITORY privilege on the SYSTEM level, the privileges to create databases in the default catalog, to create tables in any database, and to load and export data on any table.
-
Grant the privileges to perform database-level backup and restore operations:
The privileges to perform database-level backup and restore operations require the REPOSITORY privilege on the SYSTEM level, the privilege to create databases in the default catalog, the privilege to create tables in any database, the privilege to load data into any table, and the privilege export data from any table in the database to be backed up.
-
Grant the privileges to perform table-level backup and restore operations:
The privileges to perform table-level backup and restore operations require the REPOSITORY privilege on the SYSTEM level, the privilege to create tables in corresponding databases, the privilege to load data into any table in the database, and the privilege to export data from the table to be backed up.
-
Grant the privileges to perform partition-level backup and restore operations:
The privileges to perform partition-level backup and restore operations require the REPOSITORY privilege on the SYSTEM level, and the privilege to load and export data on the corresponding table.
For the best practices of multi-service access control, see Multi-service access control.