- 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. You can specify the following properties:
Property Description AGENT_TYPEType of the agent in the current execution context. This property can have one of the following values:
SNOWFLAKE_INTELLIGENCE, if the current execution context is inside a Snowflake Intelligence agent.CORTEX_CODE_CLI, if the current context is a Cortex Code CLI client.CORTEX_CODE_DESKTOP, if the current context is a Cortex Code Desktop client.CORTEX_CODE_SNOWSIGHT, if the current context is a Cortex Code UI (Snowsight) client.- NULL, if no agent is active in the current context.
AGENT_DATABASEName of the database that contains the agent. For Snowflake Intelligence agents, this is the database component of the agent’s fully qualified name.
If the agent is not a database-level object (for example, a Cortex Lite Agent), or if no agent is active, the value is NULL.
AGENT_SCHEMAName of the schema that contains the agent. For Snowflake Intelligence agents, this is the schema component of the agent’s fully qualified name.
If the agent is not a schema-level object (for example, a Cortex Lite Agent), or if no agent is active, the value is NULL.
AGENT_NAMEName of the agent in the current execution context. For Snowflake Intelligence agents, this is the entity name. For other agent types, this is the client type name.
If no agent is active, the value is NULL.
'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 properties and functions in this namespace when testing policies, use the corresponding POLICY_CONTEXT arguments. For example, use
SNOWFLAKE$CURRENT_AGENT_NAMEto simulate theAGENT_NAMEproperty, orSNOWFLAKE$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:
- Retrieving information about the current agent
- Checking role activation in the current context
- Checking database role activation in the current context
Retrieving information about the current agent¶
The following example returns the type and name of the agent in the current execution 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: