ALTER FUNCTION | Snowflake Documentation (original) (raw)

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

The syntax for ALTER FUNCTION varies depending on which language you’re using as the UDF handler.

Java handler

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) RENAME TO

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET SECURE

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

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET [ LOG_LEVEL = '' ] [ TRACE_LEVEL = '' ] [ EXTERNAL_ACCESS_INTEGRATIONS = ( [ , ... ] ) ] [ SECRETS = ( '' = [ , '' = ... ] ) ] [ COMMENT = '' ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET TAG = '' [ , = '' ... ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) UNSET TAG [ , ... ]

JavaScript handler

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) RENAME TO

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET SECURE

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

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET [ LOG_LEVEL = '' ] [ TRACE_LEVEL = '' ] [ COMMENT = '' ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET TAG = '' [ , = '' ... ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) UNSET TAG [ , ... ]

Python handler

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) RENAME TO

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET SECURE

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

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET [ LOG_LEVEL = '' ] [ TRACE_LEVEL = '' ] [ EXTERNAL_ACCESS_INTEGRATIONS = ( [ , ... ] ) ] [ SECRETS = ( '' = [ , '' = ... ] ) ] [ COMMENT = '' ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET TAG = '' [ , = '' ... ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) UNSET TAG [ , ... ]

Scala handler

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) RENAME TO

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET SECURE

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

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET [ LOG_LEVEL = '' ] [ TRACE_LEVEL = '' ] [ EXTERNAL_ACCESS_INTEGRATIONS = ( [ , ... ] ) ] [ SECRETS = ( '' = [ , '' = ... ] ) ] [ COMMENT = '' ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET TAG = '' [ , = '' ... ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) UNSET TAG [ , ... ]

SQL handler

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) RENAME TO

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET SECURE

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

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET [ LOG_LEVEL = '' ] [ TRACE_LEVEL = '' ] [ COMMENT = '' ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET TAG = '' [ , = '' ... ]

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) UNSET TAG [ , ... ]

External functions

Any language handler

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET API_INTEGRATION =

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET HEADERS = ( [ '' = '' [ , '' = '' ... ] ] )

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET CONTEXT_HEADERS = ( [ [ , ...] ] )

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET MAX_BATCH_ROWS =

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET COMPRESSION =

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) SET { REQUEST_TRANSLATOR | RESPONSE_TRANSLATOR } =

ALTER FUNCTION [ IF EXISTS ] ( [ , ... ] ) 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.

_argdatatype_ [ , ... ]

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 = '_loglevel_'

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, seeSetting levels for logging, metrics, and tracing.

TRACE_LEVEL = '_tracelevel_'

Controls how trace events are ingested into the event table.

For information about levels, see TRACE_LEVEL. For information about setting trace level, seeSetting levels for logging, metrics, and tracing.

EXTERNAL_ACCESS_INTEGRATIONS = ( _integrationname_ [ , ... ] )

The names of external access integrations needed in order for this function’s handler code to access external networks.

An external access integration contains network rules andsecrets that specify the external locations and credentials (if any) needed for handler code to make requests of an external network, such as an external REST API.

For more information, refer to External network access overview.

SECRETS = ( '_secretvariablename_' = _secretname_ [ , ... ] )

Assigns the names of secrets to variables so that you can use the variables to reference the secrets when retrieving information from secrets in handler code.

This parameter’s value is a list of assignment expressions with the following parts:

COMMENT = '_stringliteral_'

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

TAG _tagname_ = '_tagvalue_' [ , _tagname_ = '_tagvalue_' , ... ]

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 _newname_

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 _newname_ value that includes the new database and/or schema name in the form_dbname_._schemaname_._objectname_ or _schemaname_._objectname_, respectively.

Note

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

External functions

RENAME TO _newname_

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.

_apiintegrationname_

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 = ( '_header1_' = '_value_' [ , '_header2_' = '_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 = ( [ _contextfunction1_ [ , _contextfunction2_ ... ] ] )

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 = _compressiontype_

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 _compressiontype_, see CREATE EXTERNAL FUNCTION.

{ REQUEST_TRANSLATOR | RESPONSE_TRANSLATOR } = _udfname_

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 operation must have the followingprivileges 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.

The USAGE privilege on the parent database and schema are required to perform operations on any object in a 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 onsecurable objects, see Overview of Access Control.

Usage notes

User-defined functions

External functions

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;