Categories:

Context functions (General)

IS_ROLE_ACTIVATED (SYS_CONTEXT function)

Returns the VARCHAR value 'TRUE' if an account role is activated. You can check activation in the session context or in the current execution context.

See also:

IS_DATABASE_ROLE_ACTIVATED (SYS_CONTEXT function) , SYS_CONTEXT (SNOWFLAKE$CURRENT namespace) , SYS_CONTEXT (SNOWFLAKE$SESSION namespace)

Syntax

Check role activation in the session:

SYS_CONTEXT(
  'SNOWFLAKE$SESSION' ,
  'IS_ROLE_ACTIVATED' ,
  '<role>'
)

Check role activation in the current execution context:

SYS_CONTEXT(
  'SNOWFLAKE$CURRENT' ,
  'IS_ROLE_ACTIVATED' ,
  '<role>'
)

Arguments

'SNOWFLAKE$SESSION'

Specifies that you want to check role activation in the session context.

'SNOWFLAKE$CURRENT'

Specifies that you want to check role activation in the current execution context. The current execution context can differ from the session context inside an owner’s rights executable or during an agent invocation. For more information, see SYS_CONTEXT (SNOWFLAKE$CURRENT namespace).

'IS_ROLE_ACTIVATED'

Calls the IS_ROLE_ACTIVATED function.

'role'

Specifies the account role to check.

Returns

The function returns one of the following VARCHAR values:

  • 'TRUE' if the account role is activated in the specified context.
  • 'FALSE' if the account role is not activated or if the account role is not valid.

To compare this return value against the BOOLEAN value TRUE or FALSE, cast the return value to BOOLEAN. For example:

SELECT SYS_CONTEXT('SNOWFLAKE$SESSION', 'IS_ROLE_ACTIVATED', 'my_role')::BOOLEAN = TRUE;

Usage notes

  • When you use the SNOWFLAKE$SESSION namespace, the function checks whether the role is in the role hierarchy of the session’s primary or secondary roles.

  • When you use the SNOWFLAKE$CURRENT namespace, the function checks the innermost execution context. Inside an owner’s rights stored procedure, for example, this reflects the owner’s activated roles, not the caller’s.

  • To simulate the result of this function in a policy, use the SNOWFLAKE$SESSION_ACTIVATED_ROLES or SNOWFLAKE$CURRENT_ACTIVATED_ROLES list argument with the POLICY_CONTEXT function.

Examples

The following example returns 'TRUE' if the role my_role is in the role hierarchy of the session’s primary or secondary roles:

SELECT SYS_CONTEXT('SNOWFLAKE$SESSION', 'IS_ROLE_ACTIVATED', 'my_role');

The following example checks whether the role analyst is activated in the current execution context:

SELECT SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_ROLE_ACTIVATED', 'analyst');