user_defined_functions
Creates, updates, deletes, gets or lists a user_defined_functions resource.
Overview
| Name | user_defined_functions |
| Type | Resource |
| Id | snowflake.functions.user_defined_functions |
Fields
The following fields are returned by SELECT queries:
- get
- list
successful
| Name | Datatype | Description |
|---|---|---|
name | string | The name of the UDF (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
database_name | string | The name of the database in which the function/procedure exists. (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
schema_name | string | The name of the schema in which the function/procedure exists. (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
arguments | array | List of arguments for the function/procedure |
body | string | Function/procedure definition |
comment | string | Specifies a comment for the function/procedure |
created_on | string (date-time) | The date and time when the function/procedure was created |
is_aggregate | boolean | Specifies whether the UDF is an aggregate function. Applicable only for Python language type |
is_builtin | boolean | If the function/procedure is built-in or not (user-defined) |
is_memoizable | boolean | Indicates whether the function is memoizable. Applicable only for Python language type. |
is_secure | boolean | Specifies whether the function/procedure is secure or not |
is_table_function | boolean | True if the UDF is a table function; false otherwise. |
is_temporary | boolean | Specifies whether the UDF is temporary or not |
language_config | object | Language that the function/procedure is written in |
max_num_arguments | integer | The maximum number of arguments |
min_num_arguments | integer | The minimum number of arguments |
owner | string | Role that owns the function/procedure (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
owner_role_type | string | The type of role that owns the function/procedure (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
return_type | object | Return type of the function/procedure. Should be a SQL data type or a table |
valid_for_clustering | boolean | True if the UDF is valid for clustering; false otherwise. |
A snowflake UDF
| Name | Datatype | Description |
|---|---|---|
name | string | The name of the UDF (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
database_name | string | The name of the database in which the function/procedure exists. (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
schema_name | string | The name of the schema in which the function/procedure exists. (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
arguments | array | List of arguments for the function/procedure |
body | string | Function/procedure definition |
comment | string | Specifies a comment for the function/procedure |
created_on | string (date-time) | The date and time when the function/procedure was created |
is_aggregate | boolean | Specifies whether the UDF is an aggregate function. Applicable only for Python language type |
is_builtin | boolean | If the function/procedure is built-in or not (user-defined) |
is_memoizable | boolean | Indicates whether the function is memoizable. Applicable only for Python language type. |
is_secure | boolean | Specifies whether the function/procedure is secure or not |
is_table_function | boolean | True if the UDF is a table function; false otherwise. |
is_temporary | boolean | Specifies whether the UDF is temporary or not |
language_config | object | Language that the function/procedure is written in |
max_num_arguments | integer | The maximum number of arguments |
min_num_arguments | integer | The minimum number of arguments |
owner | string | Role that owns the function/procedure (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
owner_role_type | string | The type of role that owns the function/procedure (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
return_type | object | Return type of the function/procedure. Should be a SQL data type or a table |
valid_for_clustering | boolean | True if the UDF is valid for clustering; false otherwise. |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
get | select | database_name, schema_name, name_with_args, endpoint | Fetch a UDF | |
list | select | database_name, schema_name, endpoint | like | List UDFs |
create | insert | database_name, schema_name, endpoint, name, arguments, return_type, language_config | createMode, copyGrants | Create a UDF |
delete | delete | database_name, schema_name, name_with_args, endpoint | ifExists | Delete a UDF |
rename | exec | database_name, schema_name, name_with_args, targetDatabase, targetSchema, targetName, endpoint | ifExists | Rename 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.
| Name | Datatype | Description |
|---|---|---|
database_name | string | Identifier (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. |
endpoint | string | Organization and account identifier (orgname-accountname) (default: orgname-accountname) |
name_with_args | string | Function's name with Args |
schema_name | string | Identifier (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. |
targetDatabase | string | Database of the target resource. Defaults to the source's database |
targetName | string | Name of the target resource. |
targetSchema | string | Schema of the target resource. Defaults to the source's schema |
copyGrants | boolean | Parameter to enable copy grants when creating the object. |
createMode | string | 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. |
ifExists | boolean | 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. |
like | string | Parameter to filter the command output by resource name. Uses case-insensitive pattern matching, with support for SQL wildcard characters. |
SELECT examples
- get
- list
Fetch a UDF
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.functions.user_defined_functions
WHERE database_name = '{{ database_name }}' -- required
AND schema_name = '{{ schema_name }}' -- required
AND name_with_args = '{{ name_with_args }}' -- required
AND endpoint = '{{ endpoint }}' -- required
;
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.functions.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
- Manifest
Create a UDF
INSERT INTO snowflake.functions.user_defined_functions (
name,
is_temporary,
is_aggregate,
is_memoizable,
is_secure,
arguments,
return_type,
language_config,
comment,
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 }}'
RETURNING
status
;
# Description fields are for documentation purposes
- name: user_defined_functions
props:
- name: database_name
value: "{{ database_name }}"
description: Required parameter for the user_defined_functions resource.
- name: schema_name
value: "{{ schema_name }}"
description: Required parameter for the user_defined_functions resource.
- name: endpoint
value: "{{ endpoint }}"
description: Required parameter for the user_defined_functions resource.
- name: name
value: "{{ name }}"
description: |
The name of the UDF
- name: is_temporary
value: {{ is_temporary }}
description: |
Specifies whether the UDF is temporary or not
- name: is_aggregate
value: {{ is_aggregate }}
description: |
Specifies whether the UDF is an aggregate function. Applicable only for Python language type
- name: is_memoizable
value: {{ is_memoizable }}
description: |
Indicates whether the function is memoizable. Applicable only for Python language type.
- name: is_secure
value: {{ is_secure }}
description: |
Specifies whether the function/procedure is secure or not
- name: arguments
description: |
List of arguments for the function/procedure
value:
- name: "{{ name }}"
datatype: "{{ datatype }}"
default_value: "{{ default_value }}"
- name: return_type
description: |
Return type of the function/procedure. Should be a SQL data type or a table
value:
type: "{{ type }}"
- name: language_config
description: |
Language that the function/procedure is written in
value:
language: "{{ language }}"
called_on_null_input: {{ called_on_null_input }}
is_volatile: {{ is_volatile }}
- name: comment
value: "{{ comment }}"
description: |
Specifies a comment for the function/procedure
- name: body
value: "{{ body }}"
description: |
Function/procedure definition
- name: createMode
value: "{{ createMode }}"
description: 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.
description: 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.
- name: copyGrants
value: {{ copyGrants }}
description: Parameter to enable copy grants when creating the object.
description: Parameter to enable copy grants when creating the object.
DELETE examples
- delete
Delete a UDF
DELETE FROM snowflake.functions.user_defined_functions
WHERE database_name = '{{ database_name }}' --required
AND schema_name = '{{ schema_name }}' --required
AND name_with_args = '{{ name_with_args }}' --required
AND endpoint = '{{ endpoint }}' --required
AND ifExists = '{{ ifExists }}'
;
Lifecycle Methods
- rename
Rename a UDF
EXEC snowflake.functions.user_defined_functions.rename
@database_name='{{ database_name }}' --required,
@schema_name='{{ schema_name }}' --required,
@name_with_args='{{ name_with_args }}' --required,
@targetDatabase='{{ targetDatabase }}' --required,
@targetSchema='{{ targetSchema }}' --required,
@targetName='{{ targetName }}' --required,
@endpoint='{{ endpoint }}' --required,
@ifExists={{ ifExists }}
;