Categories:

Context functions (General)

SYS_CONTEXT (SNOWFLAKE$APPLICATION namespace)¶

Returns information about the context in which a statement is executed within a Snowflake Native App.

You can call this function in the following contexts:

  • A stored procedure or Streamlit app that is configured to use owner’s rights and is within or owned by a Snowflake Native App.

  • A UDF, view, or policy that is owned by a Snowflake Native App.

  • A UDF, view, or policy that is part of the shared data content of a Snowflake Native App.

In any other context, the function returns NULL.

See also:

SYS_CONTEXT , SYS_CONTEXT (SNOWFLAKE$ENVIRONMENT namespace) , SYS_CONTEXT (SNOWFLAKE$ORGANIZATION namespace) , SYS_CONTEXT (SNOWFLAKE$ORGANIZATION_SESSION namespace) , SYS_CONTEXT (SNOWFLAKE$SESSION namespace) , IS_APPLICATION_ROLE_ACTIVATED (SYS_CONTEXT function)

Syntax¶

Syntax for retrieving properties:

SYS_CONTEXT(
  'SNOWFLAKE$APPLICATION' ,
  '<property>'
)
Copy

Syntax for calling functions:

SYS_CONTEXT(
  'SNOWFLAKE$APPLICATION' ,
  '<function>' , '<argument>' [ , ... ]
)
Copy

Arguments¶

'SNOWFLAKE$APPLICATION'

Specifies that you want to retrieve a property or call a function to return context information about the application in which the function is called.

'property'

Name of the property that you want to retrieve. You can specify the following properties:

Property

Description

NAME

Name of the application.

CURRENT_VERSION

Current version of the application in which the current SQL statement is executed.

The value of the CURRENT_VERSION property can differ from the INSTALLED_VERSION property in the following situations:

  • The SQL statement is executed in a setup script that upgrades the application to a new version.

    In this case, CURRENT_VERSION is the new version, and INSTALLED_VERSION is the currently installed version that is being upgraded.

  • A long-running procedure or query started executing before an upgrade completed.

    In this case, CURRENT_VERSION is the version when the procedure or query started executing, and INSTALLED_VERSION is the version after the upgrade completed.

CURRENT_PATCH

Current patch number of the application in which the current SQL statement is executed.

INSTALLED_VERSION

Installed version of the application in which the current SQL statement is executed.

INSTALLED_PATCH

Installed patch number of the application in which the current SQL statement is executed.

IS_DEV_MODE

TRUE if the application is in development mode; otherwise, FALSE.

To compare this value against the BOOLEAN value TRUE or FALSE, cast the value to BOOLEAN. For example:

SELECT SYS_CONTEXT('SNOWFLAKE$APPLICATION', 'IS_DEV_MODE')::BOOLEAN = TRUE;
Copy
'function'

Name of the function that you want to call. 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:

Usage notes¶

  • If you are specifying the function call in a double-quoted string in a shell, escape the $ character with a backslash (\) so that $APPLICATION is not interpreted as a shell variable.

    For example, if you are using Snowflake CLI and you are specifying the SQL statement as a command-line argument in double quotes:

    snow sql --query "SELECT SYS_CONTEXT('SNOWFLAKE\$APPLICATION', 'NAME');"
    
    Copy

Examples¶

The following example returns the current version of the application:

SELECT SYS_CONTEXT('SNOWFLAKE$APPLICATION', 'CURRENT_VERSION');
Copy