Skip to main content
Grants roles or privileges on specific objects to a user, a role, or an external group. For more information about the privileges that can be granted, see Privilege items. For more information about creating an external group, see Group Provider. After a GRANT operation is performed, you can run SHOW GRANTS to view detailed privilege information or run REVOKE to revoke a privilege or role. Before a GRANT operation is performed, make sure that the related user or role has been created. For more information, see CREATE USER and CREATE ROLE. Tip
  • Only users with the user_admin role 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 OPTION keyword to other users and roles.

Syntax

Grant privileges to roles or users

System

AI functions and providers

AI FUNCTION uses an unqualified public builtin family name without a parameter signature. 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

Example: 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 TABLE is 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 TABLE is not supported.
Caution 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 user jack.
Example 2: Grant the privilege to load data into all tables of database db1 to role my_role.
Example 3: Grant the privileges to read, update, and load data into table tbl1 of database db1 to user jack.
Example 4: Grant the privilege to use all the resources to user jack.
Example 5: Grant the privilege to use resource spark_resource to user jack.
Example 6: Grant the privilege to use resource spark_resource to role my_role.
Example 7: Grant the privilege to read data from table sr_member to user jack and allow user jack to grant this privilege to other users or roles (by specifying WITH GRANT OPTION).
Example 8: Grant system-defined roles db_admin, user_admin, and cluster_admin to user user_platform.
Example 9: Allow user jack to perform operations as user rose.
Example 10: Grant system-defined roles 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

And you can further grant the privilege to use UDFs in queries:

Grant global write privileges on tables

Grant read-only privileges on a specific external catalog

Tip For views in external catalogs, you can query only Hive table views (since v3.1).

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.