CREATE DATA METRIC FUNCTION

statementsupportedGovernance (policies, tags, data quality)Enterprise+

docs.snowflake.com ↗

Object: DATA METRIC FUNCTION

Creates a new data metric function (DMF) in the current or specified schema, or replaces an existing data metric function. After creating a DMF, apply it to a table column using an ALTER TABLE … ALTER COLUMN command or a view column using the ALTER VIEW command. This command supports the following variants: - CREATE OR ALTER DATA METRIC FUNCTION: Creates a new data metric function if it doesn’t exist or alters an existing data metric function. - DEFINE DATA METRIC FUNCTION: Declarative definition of a data metric function’s target state inside a DCM project. Data Quality Monitoring requires Enterprise Edition. To inquire about upgrading, please contact Snowflake Support.

Syntax

supportedpartialnot supportednot scored

CREATE [ OR REPLACE ] [ SECURE ] DATA METRIC FUNCTION [ IF NOT EXISTS ] <name>
  ( <table_arg> TABLE( <col_arg> <data_type> [ , ... ] )
    [ , <table_arg> TABLE( <col_arg> <data_type> [ , ... ] ) ] )
  RETURNS NUMBER [ [ NOT ] NULL ]
  [ LANGUAGE SQL ]
  [ COMMENT = '<string_literal>' ]
  AS
  '<expression>'

For more information, see CREATE OR ALTER DATA METRIC FUNCTION usage notes and CREATE OR ALTER <object>.

CREATE [ OR ALTER ] DATA METRIC FUNCTION ...

Parameters

NameRequiredDescription
namerequiredIdentifier for the DMF; must be unique for your schema. In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive. For more information, see Identifier requirements.
( table_arg TABLE( col_arg data_type [ , ... ] ) [ , table_arg TABLE( col_arg data_type [ , ... ] ) ] )requiredThe signature for the DMF, which is used as input for the expression. You must specify: An argument name for each table (table_arg). For each table, an argument name for at least one column, along with its data type (col_arg data_type). You can optionally specify arguments for additional columns and their data types. The columns must be in the same table and cannot reference a different table.
RETURNS NUMBERrequiredThe data type of the output of the function. The data type can only be NUMBER.
AS expressionrequiredSQL expression that determines the output of the function. The expression must be deterministic and return a scalar value. The expression can reference other table objects, such as by using a WITH clause or a WHERE clause. The delimiters around the expression can be either single quotes or a pair of dollar signs. Using $$ as the delimiter makes it easier to write expressions that contain single quotes. If the delimiter for the expression is the single quote character, then any single quotes within expression (for example, string literals) must be escaped by single quotes. The expression does not support the following: Using nondeterministic functions (for example, CURRENT_TIME). Referencing an object that depends on a UDF or UDTF. Returning a nonscalar output.
SECUREoptionalSpecifies that the data metric function is secure. For more information, see Protecting Sensitive Information with Secure UDFs and Stored Procedures.
LANGUAGE SQLoptionalSpecifies the language used to write the expression. SQL is the only supported language.
COMMENT = 'string_literal'optionalA comment for the DMF.

Access control requirements

Privilege | Object | Notes CREATE DATA METRIC FUNCTION | Schema | The privilege only enables the creation of data metric functions in the schema. If you want to enable the creation of user-defined functions, such as SQL or Java UDFs, the role must have the CREATE FUNCTION privilege.

General usage notes

- If you want to update an existing data metric function and need to see the current definition of the function, run the DESCRIBE FUNCTION (DMF) command or call the GET_DDL function. - Regarding metadata: Attention Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake. - The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement. - CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.

CREATE OR ALTER DATA METRIC FUNCTION usage notes

You can’t modify the DMF’s arguments. Specifying new arguments creates a new overloaded DMF.

Example: Alter a data metric function using the CREATE OR ALTER DATA METRIC FUNCTION command

Alters the single-table data metric function created in the example above to set security and comment.

Referenced by