Categories:

Data metric functions

ACCEPTED_VALUES (system data metric function)¶

Returns the number of records where the value of a column does not match a Boolean expression.

Syntax¶

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

Arguments¶

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.

Allowed data types¶

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

Returns¶

The function returns a NUMBER value.

Access control requirements¶

To use a system DMF, choose one of the following access control approaches:

  • Grant the DATA_METRIC_USER database role to the table owner role, which is the role with the OWNERSHIP privilege on the table. This database role has the USAGE privilege on the SNOWFLAKE.CORE schema and the USAGE privilege on all system DMFs in the SNOWFLAKE.CORE schema.

    Additionally, grant the following privileges to the table owner role:

    Privilege

    Object

    Notes

    EXECUTE DATA METRIC FUNCTION

    Account

    This privilege enables you to control which roles have access to serverless compute resources to call the system DMF.

    USAGE

    Database, schema

    These objects are the database and schema that contain the table.referenced table with which the DMF is associated.

  • Grant IMPORTED PRIVILEGES on the SNOWFLAKE database to the table owner role. For information, see Enabling other roles to use schemas in the SNOWFLAKE database.

  • Use the ACCOUNTADMIN role.

For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.

For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

Usage notes¶

  • 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 to automate data quality checks.

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

  • You cannot associate this function with the same column more than once.

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

Examples¶

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);
Copy

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'));
Copy