Skip to main content

user_defined_functions

Creates, updates, deletes, gets or lists a user_defined_functions resource.

Overview

Nameuser_defined_functions
TypeResource
Idsnowflake.user_defined_function.user_defined_functions

Fields

The following fields are returned by SELECT queries:

A snowflake UDF

NameDatatypeDescription
namestringThe name of the UDF (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
database_namestringThe name of the database in which the function/procedure exists. (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
schema_namestringThe name of the schema in which the function/procedure exists. (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
argumentsarrayList of arguments for the function/procedure
bodystringFunction/procedure definition
commentstringSpecifies a comment for the function/procedure
created_onstring (date-time)The date and time when the function/procedure was created
is_aggregatebooleanSpecifies whether the UDF is an aggregate function. Applicable only for Python language type
is_builtinbooleanIf the function/procedure is built-in or not (user-defined)
is_memoizablebooleanIndicates whether the function is memoizable. Applicable only for Python language type.
is_securebooleanSpecifies whether the function/procedure is secure or not
is_table_functionbooleanTrue if the UDF is a table function; false otherwise.
is_temporarybooleanSpecifies whether the UDF is temporary or not
language_configobject
max_num_argumentsintegerThe maximum number of arguments
min_num_argumentsintegerThe minimum number of arguments
ownerstringRole that owns the function/procedure (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
owner_role_typestringThe type of role that owns the function/procedure (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
return_typeobject
valid_for_clusteringbooleanTrue if the UDF is valid for clustering; false otherwise.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
list_user_defined_functionsselectdatabase_name, schema_name, endpointlikeList UDFs
fetch_user_defined_functionselectdatabase_name, schema_name, nameWithArgs, endpointFetch a UDF
create_user_defined_functioninsertdatabase_name, schema_name, endpointcreateMode, copyGrantsCreate a UDF
delete_user_defined_functiondeletedatabase_name, schema_name, nameWithArgs, endpointifExistsDelete a UDF
rename_user_defined_functionexecdatabase_name, schema_name, nameWithArgs, targetDatabase, targetSchema, targetName, endpointifExistsRename a UDF

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
database_namestringIdentifier (i.e. name) for the database to which the resource belongs. You can use the /api/v2/databases GET request to get a list of available databases.
endpointstringOrganization and Account Name (default: orgid-acctid)
nameWithArgsstringFunction's name with Args
schema_namestringIdentifier (i.e. name) for the schema to which the resource belongs. You can use the /api/v2/databases/{database}/schemas GET request to get a list of available schemas for the specified database.
targetDatabasestringDatabase of the target resource. Defaults to the source's database
targetNamestringName of the target resource.
targetSchemastringSchema of the target resource. Defaults to the source's schema
copyGrantsbooleanQuery parameter to enable copy grants when creating the object.
createModestringQuery parameter allowing support for different modes of resource creation. Possible values include: - errorIfExists: Throws an error if you try to create a resource that already exists. - orReplace: Automatically replaces the existing resource with the current one. - ifNotExists: Creates a new resource when an alter is requested for a non-existent resource.
ifExistsbooleanQuery parameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn't exist.
likestringQuery parameter to filter the command output by resource name. Uses case-insensitive pattern matching, with support for SQL wildcard characters.

SELECT examples

List UDFs

SELECT
name,
database_name,
schema_name,
arguments,
body,
comment,
created_on,
is_aggregate,
is_builtin,
is_memoizable,
is_secure,
is_table_function,
is_temporary,
language_config,
max_num_arguments,
min_num_arguments,
owner,
owner_role_type,
return_type,
valid_for_clustering
FROM snowflake.user_defined_function.user_defined_functions
WHERE database_name = '{{ database_name }}' -- required
AND schema_name = '{{ schema_name }}' -- required
AND endpoint = '{{ endpoint }}' -- required
AND like = '{{ like }}';

INSERT examples

Create a UDF

INSERT INTO snowflake.user_defined_function.user_defined_functions (
data__name,
data__is_temporary,
data__is_aggregate,
data__is_memoizable,
data__is_secure,
data__arguments,
data__return_type,
data__language_config,
data__comment,
data__body,
database_name,
schema_name,
endpoint,
createMode,
copyGrants
)
SELECT
'{{ name }}' --required,
{{ is_temporary }},
{{ is_aggregate }},
{{ is_memoizable }},
{{ is_secure }},
'{{ arguments }}' --required,
'{{ return_type }}' --required,
'{{ language_config }}' --required,
'{{ comment }}',
'{{ body }}',
'{{ database_name }}',
'{{ schema_name }}',
'{{ endpoint }}',
'{{ createMode }}',
'{{ copyGrants }}'
;

DELETE examples

Delete a UDF

DELETE FROM snowflake.user_defined_function.user_defined_functions
WHERE database_name = '{{ database_name }}' --required
AND schema_name = '{{ schema_name }}' --required
AND nameWithArgs = '{{ nameWithArgs }}' --required
AND endpoint = '{{ endpoint }}' --required
AND ifExists = '{{ ifExists }}';

Lifecycle Methods

Rename a UDF

EXEC snowflake.user_defined_function.user_defined_functions.rename_user_defined_function 
@database_name='{{ database_name }}' --required,
@schema_name='{{ schema_name }}' --required,
@nameWithArgs='{{ nameWithArgs }}' --required,
@targetDatabase='{{ targetDatabase }}' --required,
@targetSchema='{{ targetSchema }}' --required,
@targetName='{{ targetName }}' --required,
@endpoint='{{ endpoint }}' --required,
@ifExists={{ ifExists }};