Categories:

Data metric functions

ACCEPTED_VALUES(系统数据指标函数)

返回列值 匹配布尔表达式的记录数。

语法

SNOWFLAKE.CORE.ACCEPTED_VALUES ON ( <column>, <lambda-expression> )

实参

column

Specifies the column that contains values that are compared to the Boolean expression in lambda-expression.

lambda-expression

Specifies a lambda expression consisting of the following syntax: column -> expression.

The function returns the number of records where the value of column doesn’t match the Boolean expression. This expression can use the following operations and functions:

The column in the lambda expression always matches the column argument.

允许的数据类型

The column specified in the column and lambda-expression arguments can contain any of the following data types:

  • DATE
  • FLOAT
  • NUMBER
  • TIMESTAMP_LTZ
  • TIMESTAMP_NTZ
  • TIMESTAMP_TZ
  • VARCHAR

返回

该函数会返回 NUMBER 值。

使用说明

  • You can’t call this function directly. To learn how to associate the function with a table or view so it runs at regular intervals, see Associate a DMF.

    You can use the SYSTEM$DATA_METRIC_SCAN function to run the ACCEPTED_VALUES function against a table without associating it.

  • 您不能多次将此函数与同一列关联。

  • Renaming a column that is specified in the ACCEPTED_VALUES function breaks the association between the function and the column’s table or view. If you rename the column, you must re-associate the function with the table or view.

示例

Associate the function with table t1 so it returns the number of records where the value of the column age is not equal to five.

ALTER TABLE t1
  ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.ACCEPTED_VALUES ON (age, age -> age = 5);

Associate the function with view order_details so it returns the number of records where the value of column order_status is not in the list of strings Pending, Dispatched, and Delivered.

ALTER VIEW order_details
  ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.ACCEPTED_VALUES ON (
    order_status,
    order_status -> order_status IN ('Pending', 'Dispatched', 'Delivered'));