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¶
The syntax for ALTER FUNCTION varies depending on which language you’re using as the UDF handler.
Java handler¶
ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) RENAME TO <new_name>
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
[ LOG_LEVEL = '<log_level>' ]
[ TRACE_LEVEL = '<trace_level>' ]
[ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , <integration_name> ... ] ) ]
[ SECRETS = ( '<secret_variable_name>' = <secret_name> [ , '<secret_variable_name>' = <secret_name> ... ] ) ]
[ COMMENT = '<string_literal>' ]
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> ... ]
JavaScript handler¶
ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) RENAME TO <new_name>
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
[ LOG_LEVEL = '<log_level>' ]
[ TRACE_LEVEL = '<trace_level>' ]
[ COMMENT = '<string_literal>' ]
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> ... ]
Python handler¶
ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) RENAME TO <new_name>
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
[ LOG_LEVEL = '<log_level>' ]
[ TRACE_LEVEL = '<trace_level>' ]
[ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , <integration_name> ... ] ) ]
[ SECRETS = ( '<secret_variable_name>' = <secret_name> [ , '<secret_variable_name>' = <secret_name> ... ] ) ]
[ COMMENT = '<string_literal>' ]
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> ... ]
Scala handler¶
ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) RENAME TO <new_name>
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
[ LOG_LEVEL = '<log_level>' ]
[ TRACE_LEVEL = '<trace_level>' ]
[ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , <integration_name> ... ] ) ]
[ SECRETS = ( '<secret_variable_name>' = <secret_name> [ , '<secret_variable_name>' = <secret_name> ... ] ) ]
[ COMMENT = '<string_literal>' ]
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> ... ]
SQL handler¶
ALTER FUNCTION [ IF EXISTS ] <name> ( [ <arg_data_type> , ... ] ) RENAME TO <new_name>
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
[ LOG_LEVEL = '<log_level>' ]
[ TRACE_LEVEL = '<trace_level>' ]
[ COMMENT = '<string_literal>' ]
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> ... ]
External functions¶
Any language handler¶
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 ...
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 levels for logging, metrics, and tracing.
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 levels for logging, metrics, and tracing.
EXTERNAL_ACCESS_INTEGRATIONS = ( integration_name [ , ... ] )
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 and secrets 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 = ( 'secret_variable_name' = secret_name [ , ... ] )
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:
secret_name
as the name of a secret specified in an external access integration’s ALLOWED_AUTHENTICATION_SECRETS parameter value. That external access integration’s name must, in turn, be specified as a value of this CREATE FUNCTION call’s EXTERNAL_ACCESS_INTEGRATIONS parameter.You will receive an error if you specify a SECRETS value whose secret isn’t also included in an integration specified by the EXTERNAL_ACCESS_INTEGRATIONS parameter.
'secret_variable_name'
as the variable that will be used in handler code when retrieving information from the secret.
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 formdb_name.schema_name.object_name
orschema_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.
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¶
If using a UDF in a masking policy, ensure the data type of the column, UDF, and masking policy match. For more information, see User-defined functions in a masking policy.
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;