ALTER FUNCTION

Modifies the properties of an existing user-defined or external function.

To make any other changes to a UDF, you must drop the function (using DROP FUNCTION) and then recreate it.

See also:

Writing External Functions, User-Defined Functions Overview, CREATE FUNCTION , DROP FUNCTION , SHOW USER FUNCTIONS , DESCRIBE FUNCTION, CREATE EXTERNAL FUNCTION , DESCRIBE FUNCTION , DROP FUNCTION , SHOW EXTERNAL FUNCTIONS

Syntax

User-Defined and External Functions

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

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) SET LOG_LEVEL = '<log_level>'

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) SET TRACE_LEVEL = '<trace_level>'

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

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

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) UNSET { SECURE | LOG_LEVEL | TRACE_LEVEL | COMMENT }

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

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

External Functions

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) SET API_INTEGRATION = <api_integration_name>

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) SET HEADERS = ( [ '<header_1>' = '<value>' [ , '<header_2>' = '<value>' ... ] ] )

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) SET CONTEXT_HEADERS = ( [ <context_function_1> [ , <context_function_2> ...] ] )

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) SET MAX_BATCH_ROWS = <integer>

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) SET COMPRESSION = <compression_type>

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) SET { REQUEST_TRANSLATOR | RESPONSE_TRANSLATOR } = <udf_name>

ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) UNSET
              { COMMENT | HEADERS | CONTEXT_HEADERS | MAX_BATCH_ROWS | COMPRESSION | SECURE | REQUEST_TRANSLATOR | RESPONSE_TRANSLATOR }
Copy

Parameters

User-Defined and External Functions

name

Specifies the identifier for the UDF to alter. The identifier can contain the schema name and database name, as well as the function name. 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.

arg_data_type [ , ... ]

Specifies the arguments/input data types for the external function.

If the function accepts arguments, then the ALTER command must specify the argument types because functions support name overloading (i.e. two functions in the same schema can have the same name), and the argument types are used to identify the function.

SET ...

Specifies the properties to set for the function:

SECURE

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

LOG_LEVEL = 'log_level'

Specifies the severity level of messages that should be ingested and made available in the active event table. Messages at the specified level (and at more severe levels) are ingested.

For more information about levels, see LOG_LEVEL. For information about setting log level, see Setting Log Level.

TRACE_LEVEL = 'trace_level'

Controls how trace events are ingested into the event table.

For information about levels, see TRACE_LEVEL. For information about setting trace level, see Setting Trace Level.

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.

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.

User-Defined Functions

RENAME TO new_name

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

For more details, see Identifier requirements.

Note

When specifying the new name for the UDF, do not 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 (i.e. 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.

External Functions

RENAME TO new_name

Specifies the new identifier for the function.

The identifier does not need to be unique for the schema in which the function is created because functions are identified and resolved by their name and argument types. However, the signature (name and parameter data types) must be unique within the schema.

The name must follow the rules for Snowflake identifiers. For more details, see Identifier requirements.

Note

When specifying the new name for the external function, do not specify argument data types or parentheses; the function will continue using the same arguments as before.

api_integration_name

This is the name of the API integration object that should be used to authenticate the call to the proxy service.

More details about this parameter are in CREATE EXTERNAL FUNCTION.

HEADERS = ( 'header_1' = 'value' [ , 'header_2' = 'value' ... ] )

This clause allows users to attach key-value metadata that is sent with every request.

The value must be a constant string, not an expression.

More details about this parameter are in CREATE EXTERNAL FUNCTION.

CONTEXT_HEADERS = ( [ context_function_1 [ , context_function_2 ... ] ] )

This is similar to HEADERS, but instead of allowing only constant strings, it allows binding Snowflake context function results to HTTP headers.

Each value must be the name of a context function. The names should not be quoted.

More details about this parameter are in CREATE EXTERNAL FUNCTION.

COMPRESSION = compression_type

If this clause is specified, the JSON payload is compressed using the specified format when sent from Snowflake to the proxy service, and when sent back from the proxy service to Snowflake.

For more details about valid values of compression_type, see CREATE EXTERNAL FUNCTION.

{ REQUEST_TRANSLATOR | RESPONSE_TRANSLATOR } = udf_name

Add a request translator or a response translator if the external function does not already have one or replace an existing request translator or response translator by specifying the name of a previously-created JavaScript UDF. For more information, see Using Request and Response Translators with Data for a Remote Service.

Access Control Requirements

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

Privilege

Object

Notes

USAGE

Function

Enables calling a UDF or external function.

APPLY

Tag

Enables setting a tag on the UDF or external function.

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.

User-Defined Functions

External Functions

  • There is no UNSET command for API_INTEGRATION. You can change the API_INTEGRATION, but you cannot unset it. For more, see ALTER API INTEGRATION.

Examples

Rename the function function1 to function2:

ALTER FUNCTION IF EXISTS function1(number) RENAME TO function2;
Copy

Convert a regular function function2 to a secure function:

ALTER FUNCTION function2(number) SET SECURE;
Copy

External Functions

Change the API Integration for an external function:

ALTER FUNCTION function4(number) SET API_INTEGRATION = api_integration_2;
Copy

Set the maximum number of rows per batch for an external function:

ALTER FUNCTION function5(number) SET MAX_BATCH_ROWS = 100;
Copy