- 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.
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: