Categories:

Context functions (General)

SYS_CONTEXT

返回关于调用该函数的上下文信息。

See also:

SYS_CONTEXT (SNOWFLAKE$APPLICATION 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)

语法

用来检索属性的语法:

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

用来调用函数的语法:

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

实参

'namespace'

您要检索的属性或要调用的函数的命名空间。您可以指定以下命名空间之一:

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

提供调用该函数的环境相关上下文的属性。这些属性包括关于以下内容的信息:

  • 用于调用该函数的客户端、驱动程序或库。
  • 与调用该函数的会话关联的账户。
  • 该账户的区域。
SNOWFLAKE$ORGANIZATIONFunctions providing context around the current organization.
SNOWFLAKE$ORGANIZATION_SESSION

在当前账户属于某个组织时,提供调用该函数的会话相关上下文的属性。

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' [ , ... ]

要传递给要调用的函数的实参。

返回

该函数会返回一个 VARCHAR 或 NULL 值。

  • 返回值取决于要检索的属性或要调用的函数。

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

  • 在以下情况下,该函数返回 NULL:

    • 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.
    • 属性的值或函数调用的返回值为 NULL 或不存在。

Some properties and functions return Boolean values as 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                                                                                    |
+-----------------------------------------------------------------------------------------+

访问控制要求

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

使用说明

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

示例

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