Categories:

Context functions (General)

SYS_CONTEXT

Returns information about the context in which the function is called.

See also:

SYS_CONTEXT (SNOWFLAKE$APPLICATION namespace) , SYS_CONTEXT (SNOWFLAKE$CURRENT namespace) , SYS_CONTEXT (SNOWFLAKE$ENVIRONMENT namespace) , SYS_CONTEXT (SNOWFLAKE$ORGANIZATION namespace) , SYS_CONTEXT (SNOWFLAKE$ORGANIZATION_SESSION namespace) , SYS_CONTEXT (SNOWFLAKE$SESSION namespace) , SYS_CONTEXT (SNOWFLAKE$SESSION_ATTRIBUTES namespace)

Syntax

Syntax for retrieving properties:

SYS_CONTEXT(
  '<namespace>' ,
  '<property>'
)

Syntax for calling functions:

SYS_CONTEXT(
  '<namespace>' ,
  '<function>' , '<argument>' [ , ... ]
)

Arguments

'namespace'

Namespace of the property that you want to retrieve or the function that you want to call. You can specify one of the following namespaces:

NamespaceDescription
SNOWFLAKE$APPLICATIONProperties and functions providing context around the application in which the function is called.
SNOWFLAKE$CURRENT

Properties and functions providing context around the current execution context. The current execution context can differ from the session context inside owner’s rights executables or agent invocations.

SNOWFLAKE$ENVIRONMENT

Properties providing context around the environment in which the function is called. These properties include information about:

  • The client, driver, or library that is used to call the function.
  • The account associated with the session in which the function is called.
  • The region of that account.
SNOWFLAKE$ORGANIZATIONFunctions providing context around the current organization.
SNOWFLAKE$ORGANIZATION_SESSION

Properties providing context around the session in which the function is called, when the current account is in an organization.

SNOWFLAKE$SESSIONProperties and functions providing context around the session in which the function is called.
SNOWFLAKE$SESSION_ATTRIBUTESCustom key-value attributes set for the current session using SET_SYS_CONTEXT.
'property'

Name of the property that you want to retrieve. The properties that you can specify depend on the namespace. See the documentation for a namespace for the list of properties that you can specify.

'function'

Name of the function that you want to call. The functions that you can call depend on the namespace. See the documentation for a namespace for the list of functions that you can call.

'argument' [ , ... ]

Arguments to pass to the function that you want to call.

Returns

The function returns a value whose data type depends on the property that you are retrieving or the function that you are calling. Most properties and functions return a VARCHAR value or NULL.

2026_06 behavior change bundle

When the 2026_06 behavior change bundle is enabled in your account, SYS_CONTEXT returns a value typed to match the property or function that you access instead of always returning VARCHAR. The following properties and functions return a typed value:

NamespaceProperty or functionReturn type
SNOWFLAKE$SESSIONIDNUMBER
SNOWFLAKE$SESSIONIS_ROLE_ACTIVATEDBOOLEAN
SNOWFLAKE$CURRENTIS_ROLE_ACTIVATEDBOOLEAN
SNOWFLAKE$CURRENTIS_AGENT_ACTIVATEDBOOLEAN
SNOWFLAKE$APPLICATIONCURRENT_PATCHNUMBER
SNOWFLAKE$APPLICATIONINSTALLED_PATCHNUMBER
SNOWFLAKE$APPLICATIONIS_DEV_MODEBOOLEAN
SNOWFLAKE$APPLICATIONIS_APPLICATION_ROLE_ACTIVATEDBOOLEAN
SNOWFLAKE$APPLICATIONIS_CONFIGURATION_SETBOOLEAN
SNOWFLAKE$ORGANIZATIONIS_USER_IMPORTEDBOOLEAN
SNOWFLAKE$ORGANIZATIONIS_GROUP_IMPORTEDBOOLEAN
SNOWFLAKE$ORGANIZATIONIS_GROUP_ACTIVATEDBOOLEAN

All other properties and functions continue to return VARCHAR. Existing casts, such as ::BOOLEAN or ::NUMBER, continue to work unchanged.

  • The return value depends on the property that you are retrieving or the function that you are calling.

    See the documentation for each namespace for information about the properties and return values of functions in that namespace.

  • The function returns NULL if:

    • The namespace is not accessible from within the context of the function call. For example, attempting to access properties in the SNOWFLAKE$APPLICATION namespace returns NULL if you are calling the function outside of application code.
    • The value of the property or the return value of the function call is NULL or non-existent.

When SYS_CONTEXT returns VARCHAR (see the preceding note), Boolean-valued properties and functions return the string TRUE or FALSE. 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_CUSTOM_ROLE')::BOOLEAN = TRUE;
+-----------------------------------------------------------------------------------------+
| SYS_CONTEXT('SNOWFLAKE$SESSION', 'IS_ROLE_ACTIVATED', 'MY_CUSTOM_ROLE')::BOOLEAN = TRUE |
|-----------------------------------------------------------------------------------------|
| True                                                                                    |
+-----------------------------------------------------------------------------------------+

Access control requirements

See the documentation for each namespace for information about the access control requirements for the properties and functions in that namespace.

Usage notes

See the documentation for each namespace for usage notes for the properties and functions in that namespace.

Examples

See the documentation for each namespace for examples of retrieving the properties and calling the functions in that namespace.