ALTER FUNCTION (DMF)¶

Modifies the properties of an existing data metric function (DMF).

To make any other changes to a DMF, you must drop the function using a DROP FUNCTION command and recreate the DMF.

See also:

DMF command reference

Syntax¶

ALTER FUNCTION [ IF EXISTS ] <name> ( TABLE ( <col_data_type> [ , ... ] ) )
  RENAME TO <new_name>

ALTER FUNCTION [ IF EXISTS ] <name> ( TABLE ( <col_data_type> [ , ... ] ) )
  SET SECURE

ALTER FUNCTION [ IF EXISTS ] <name> ( TABLE ( <col_data_type> [ , ... ] ) )
  UNSET SECURE

ALTER FUNCTION [ IF EXISTS ] <name> ( TABLE ( <col_data_type> [ , ... ] ) )
  SET COMMENT = '<string_literal>'

ALTER FUNCTION [ IF EXISTS ] <name> ( TABLE ( <col_data_type> [ , ... ] ) )
  UNSET COMMENT

ALTER FUNCTION [ IF EXISTS ] <name> ( TABLE ( <col_data_type> [ , ... ] ) )
  SET BODY = '<sql-expression>'

ALTER FUNCTION [ IF EXISTS ] <name> ( TABLE ( <col_data_type> [ , ... ] ) )
  SET TAG <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' ... ]

ALTER FUNCTION [ IF EXISTS ] <name> ( TABLE ( <col_data_type> [ , ... ] ) )
  UNSET TAG <tag_name> [ , <tag_name> ... ]
Copy

Parameters¶

name

Specifies the identifier for the DMF to alter.

If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive.

For more information, see Identifier requirements.

TABLE( col_data_type [ , ... ] )

Specifies the data type of the argument(s) (column(s)) for the DMF. The argument types are necessary because DMFs support name overloading, where two DMFs in the same schema can have the same name. The argument data types are used to identify the DMF you want to alter.

RENAME TO new_name

Specifies the new identifier for the DMF; the combination of the identifier and existing argument data types must be unique for the schema.

For more information, see Identifier requirements.

Note

When specifying the new name for the UDF, don’t specify argument data types or parentheses; specify only the new name.

You can move the object to a different database and/or schema while optionally renaming the object. To do so, specify a qualified new_name value that includes the new database and/or schema name in the form db_name.schema_name.object_name or schema_name.object_name, respectively.

Note

  • The destination database and/or schema must already exist. In addition, an object with the same name cannot already exist in the new location; otherwise, the statement returns an error.

  • Moving an object to a managed access schema is prohibited unless the object owner (that is, the role that has the OWNERSHIP privilege on the object) also owns the target schema.

When an object is renamed, other objects that reference it must be updated with the new name.

SET ...

Specifies the properties to set for the DMF:

SECURE

Specifies whether a function is secure. For more information, see Protecting Sensitive Information with Secure UDFs and Stored Procedures.

COMMENT = 'string_literal'

Adds a comment or overwrites the existing comment for the function. The value you specify is displayed in the DESCRIPTION column in the SHOW FUNCTIONS and SHOW USER FUNCTIONS output.

BODY = sql-expression

SQL expression that determines the output of the function. The expression must be deterministic and return a scalar value.

For information, see CREATE DATA METRIC FUNCTION.

TAG tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ]

Specifies the tag name and the tag string value.

The tag value is always a string, and the maximum number of characters for the tag value is 256.

For information about specifying tags in a statement, see Tag quotas for objects and columns.

UNSET ...

Specifies the properties to unset for the function, which resets them to the defaults.

  • SECURE

  • COMMENT

  • TAG tag_name [ , tag_name ... ]

Access control requirements¶

A role used to execute this SQL command must have the following privileges at a minimum:

Privilege

Object

Notes

OWNERSHIP

Data metric function

APPLY

Tag

Enables setting a tag on the DMF.

Note that operating on any object in a schema also requires the USAGE privilege on the parent database and schema.

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¶

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

Example¶

Make the DMF a secure DMF:

ALTER FUNCTION governance.dmfs.count_positive_numbers(
arg_t TABLE(
  arg_c1 NUMBER,
  arg_c2 NUMBER,
  arg_c3 NUMBER
))
SET SECURE;
Copy