Categories:

Context functions (Session Object)

IS_GRANTED_TO_INVOKER_ROLE

如果 INVOKER_ROLE 函数返回的角色根据调用函数的上下文继承实参中指定角色的权限,则返回 TRUE。

INVOKER_ROLE 函数仅标识并返回执行 SQL 语句的对象的账户角色。不支持数据库角色。

语法

IS_GRANTED_TO_INVOKER_ROLE( '<string_literal>' )

实参

'string_literal'

角色的名称。

使用说明

  • If using the IS_GRANTED_TO_INVOKER_ROLE function with masking policy or a row access policy, verify that your Snowflake account is Enterprise Edition or higher.

  • 只能传递一个角色名称作为实参。

  • 下表总结了可以在其中调用函数的上下文以及 Snowflake 评估的角色层次结构。

    ContextEvaluated role
    UserCURRENT_ROLE
    TableCURRENT_ROLE.
    ViewView owner role.
    UDFUDF owner role.
    Stored procedure with caller’s rightCURRENT_ROLE.
    Stored procedure with owner’s rightStored procedure owner role.
    TaskTask owner role.
    StreamThe role that queries a given stream.
  • If prefer to evaluate the role hierarchy for the current session, call IS_ROLE_IN_SESSION instead.

示例

直接调用该函数:

IS_GRANTED_TO_INVOKER_ROLE('ANALYST')

--------------------------------------+
IS_GRANTED_TO_INVOKER_ROLE('ANALYST') |
--------------------------------------+
                TRUE                  |
--------------------------------------+

在掩码策略正文中指定该函数:

CREATE OR REPLACE MASKING POLICY mask_string AS
(val string) RETURNS string ->
CASE
  WHEN IS_GRANTED_TO_INVOKER_ROLE('ANALYST') then val
  ELSE '*******'
END;