- Categories:
Context functions (General)
SYS_ CONTEXT (SNOWFLAKE$SESSION_ ATTRIBUTES namespace)¶
Returns a custom session attribute that was set using SET_SYS_CONTEXT in the
SNOWFLAKE$SESSION_ATTRIBUTES namespace.
Custom session attributes are immutable once set and persist for the duration of the session. They are useful for tracking metadata about a session, such as application context, user attributes, or audit information.
- See also:
Syntax¶
Arguments¶
'SNOWFLAKE$SESSION_ATTRIBUTES'Specifies that you want to retrieve a custom session attribute.
'key'The name of the custom attribute to retrieve. Attribute names are case-sensitive.
Returns¶
The function returns a VARCHAR value:
- The value of the specified attribute if it has been set in the current session using SET_SYS_CONTEXT.
- NULL if the attribute has not been set.
2026_06 behavior change bundle
When the 2026_06 behavior change bundle is enabled in your account, custom session
attributes in this namespace continue to return VARCHAR.
Existing casts, such as ::BOOLEAN or ::NUMBER, continue to work unchanged.
For the return type of every property and function by namespace, see SYS_CONTEXT return types.
Access control requirements¶
No special privileges are required to retrieve custom session attributes. Any user can retrieve attributes from their own session.
Usage notes¶
- Attributes must be set using SET_SYS_CONTEXT before they can be retrieved.
- Attribute names are case-sensitive.
app_contextandAPP_CONTEXTare treated as different attributes. - Attributes are session-scoped and are not visible to other sessions.
- If you are specifying the function call in a double-quoted string in a shell, escape the
$character with a backslash (\) so that$session_attributesis not interpreted as a shell variable.
Examples¶
The following example sets a custom attribute and then retrieves it:
Retrieving an attribute that has not been set returns NULL:
Attribute names are case-sensitive: