- Categories:
Context functions (General)
SYS_ CONTEXT (SNOWFLAKE$CURRENT namespace)¶
Returns information about the current execution context in which the function is called. The current execution context can differ from the session context when the function is called inside an owner’s rights executable or during an agent invocation.
You can call this function in the following contexts:
- You can call this function directly in the current session.
- You can run a caller’s rights executable (for example, a caller’s rights stored procedure) that calls this function.
- You can run an owner’s rights executable (for example, an owner’s rights stored procedure) that calls this function.
Unlike the SNOWFLAKE$SESSION namespace, calling this function in an owner’s rights executable doesn’t require the READ SESSION privilege.
In any other context, the function returns NULL.
Syntax¶
Syntax for retrieving properties:
Syntax for calling functions:
Arguments¶
'SNOWFLAKE$CURRENT'Specifies that you want to retrieve a property or call a function to return information about the current execution context.
'property'Name of the property that you want to retrieve. There are currently no properties available in this namespace.
'function'Name of the function that you want to call. When called via the SNOWFLAKE$CURRENT namespace, IS_ROLE_ACTIVATED and IS_DATABASE_ROLE_ACTIVATED check the current execution context rather than the session.
You can call the following functions:
'argument' [ , ... ]Arguments to pass to the function that you want to call.
Returns¶
The function returns a VARCHAR value or NULL:
-
The return value depends on the property that you are retrieving or the function that you are calling.
-
If you call SYS_CONTEXT with the SNOWFLAKE$CURRENT namespace outside of any of the supported contexts, the function returns NULL.
Usage notes¶
-
The SNOWFLAKE$CURRENT namespace returns values for the innermost execution context. Inside an owner’s rights stored procedure, for example, this reflects the owner’s context, not the caller’s session context. Use the SNOWFLAKE$SESSION namespace if you need session-level values instead.
-
The following table summarizes when SNOWFLAKE$CURRENT and SNOWFLAKE$SESSION return different values:
Scenario SNOWFLAKE$CURRENT SNOWFLAKE$SESSION Direct query in the session Session context Session context Inside a caller’s rights stored procedure Session context Session context Inside an owner’s rights stored procedure Owner’s context (activated roles reflect the owner; no READ SESSION required) Session context (requires READ SESSION privilege) During an agent invocation Agent’s execution context (agent properties are populated) Session context of the invoking user -
To simulate the values of functions in this namespace when testing policies, use the corresponding POLICY_CONTEXT arguments. For example, use
SNOWFLAKE$CURRENT_ACTIVATED_ROLESto simulate the result of IS_ROLE_ACTIVATED. -
If you are specifying the function call in a double-quoted string in a shell, escape the
$character with a backslash (\) so that$CURRENTis not interpreted as a shell variable.
Examples¶
The following examples demonstrate how to retrieve context information about the current execution context:
- Checking role activation in the current context
- Checking database role activation in the current context
Checking role activation in the current context¶
The following example checks whether a role is activated in the current execution context (which may differ from the session context inside an owner’s rights executable):
Checking database role activation in the current context¶
The following example checks whether a database role is activated in the current execution context: