EXPLAIN_PRIVILEGES

functionsupportedAccess control (grants, roles)

docs.snowflake.com ↗

System functions

Returns a JSON string that explains which privileges are required to execute a SQL statement. This function analyzes the authorization requirements for a given SQL statement and returns them in a structured format showing the required privileges, object types, and object names.

Syntax

supportedpartialnot supportednot scored

EXPLAIN_PRIVILEGES(
  statement => '<sql_statement>'
  [, missing_only => <boolean> ]
  [, for_role => '<role_name>' ])

Parameters

NameRequiredDescription
statement => 'sql_statement'requiredA string containing the SQL statement to analyze. The statement is analyzed to determine which privileges are required to execute it.
missing_only => booleanrequiredBoolean value that controls the output mode: false - Returns all privileges required to execute the statement, regardless of whether the current user or specified role has them. true — Returns only the privileges that are missing (not currently held by the current user or specified role). If all required privileges are present, returns {"authorized": true}. Default: false
for_role => 'role_name'requiredThe name of a role to check privileges for. This argument is used only when missing_only => true. Returns all privileges missing for the role (and its granted roles) to execute the statement.

Returns

The function returns a VARCHAR value containing a JSON object that describes the required privileges in a hierarchical structure. The JSON can contain the following node types: Permission Node — Represents a single privilege requirement: - privilege — The name of the required privilege (for example, USAGE, SELECT, OWNERSHIP). The special value <ANY> indicates that any privilege on the object is sufficient. - objectType — The type of object (for example, DATABASE, TABLE, SCHEMA, ACCOUNT). - objectName — The fully qualified name of the object. AND Node — All contained privileges are required: OR Node — At least one of the contained privileges is required: Decision Node — Indicates authorization status - authorized: true — All required privileges are present. - authorized: false — Statement cannot be authorized with privilege grants.

Usage notes

Access control requirements

You must have privileges to refer to the object by name in the SQL statement. Most commonly, this requirement is satisfied by having at least one privilege on the object. The RESOLVE ALL ON ACCOUNT privilege also meets this requirement.

See also