IS_ROLE_IN_SESSION
functionsupportedAccess control (grants, roles)Verifies whether the specified account role is in the currently active primary or secondary role hierarchy. This function looks only at the currently active set of roles, not at the roles activated in the session. The currently active roles can differ from the session roles, for example, when executing an owner’s rights procedure or a Streamlit.
Syntax
Literal — specify a role directly
IS_ROLE_IN_SESSION( '<string_literal>' )
Expression — specify a role expression
IS_ROLE_IN_SESSION( <expr> )
Column — specify a column
IS_ROLE_IN_SESSION( <column_name> )
Parameters
| Name | Required | Description |
|---|---|---|
'string_literal' | required | The name of the role. |
expr | required | An expression that returns the name of the role. |
column_name | required | The column name in a table or view that contains the name of the role. |
Usage notes
- Use one syntax.
- Name syntax: Only one role name can be passed as an argument.
- The argument must be a string and use the same casing as how the role is stored in Snowflake. For details, see Identifier requirements.
- Column syntax: Only one column can be passed as an argument.
- The column must have a STRING data type.
- Specify the column as one of the following: column_name
- table_name.column_name
- schema_name.table_name.column_name
- database_name.schema_name.table_name.column_name
- Virtual columns: A virtual column, which contains the result of a calculated value from an expression rather than the calculated value being stored in the table, is not supported. Copy code SELECT IS_ROLE_IN_SESSION(UPPER(authz_role)) FROM t1; A virtual column is supported only when the expression has an alias for the column name: Copy code CREATE VIEW v2 AS SELECT authz_role, UPPER(authz_role) AS upper_authz_role FROM t2; SELECT IS_ROLE_IN_SESSION(upper_authz_role) FROM v2;
- Policies: If you use these functions with a masking policy or row access policy, verify that your Snowflake account is Enterprise Edition or higher. Snowflake recommends using this function when the policy conditions need to evaluate role hierarchy and inherited privileges.
- Result cache: If you use this function in a masking policy or row access policy and neither the policy nor the table or column protected by the policy change from a previous query, you can use the RESULT_SCAN function to return the results of a query on the protected table. The result cache applies when using the nonliteral syntax only.
- These functions cannot be used in the materialized view definition because the functions are not deterministic and Snowflake cannot determine what data to materialize.