Categories:

DDL for User-Defined Functions, External Functions, and Stored Procedures

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

## 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 COMMENT = '<string_literal>'

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

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


### 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 }


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

SECURE

Specifies whether a function is secure. For more details, see Secure UDFs.

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.

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.

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.

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

CONTEXT_HEADERS (...)

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.

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.

## Usage Notes¶

• Moving a function to a managed access schema (using the ALTER FUNCTION ... RENAME TO syntax) is prohibited unless the function owner (i.e. the role that has the OWNERSHIP privilege on the function) also owns the target schema.

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.

### 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;


Convert a regular function function2 to a secure function:

ALTER FUNCTION function2(number) SET SECURE;


### External Functions¶

Change the API Integration for an external function:

ALTER FUNCTION function4(number) SET api_integration = api_integration_2;


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

ALTER FUNCTION function5(number) SET max_batch_rows = 100;