user_defined_functions
Creates, updates, deletes, gets or lists a user_defined_functions
resource.
Overview
Name | user_defined_functions |
Type | Resource |
Id | snowflake.user_defined_function.user_defined_functions |
Fields
Name | Datatype | Description |
---|---|---|
name | string | The name of the UDF |
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 | The date and time when the function/procedure was created |
database_name | string | The name of the database in which the function/procedure exists. |
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 | |
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 |
owner_role_type | string | The type of role that owns the function/procedure |
return_type | object | |
schema_name | string | The name of the schema in which the function/procedure exists. |
valid_for_clustering | boolean | True if the UDF is valid for clustering; false otherwise. |
Methods
Name | Accessible by | Required Params | Optional Params | Description |
---|---|---|---|---|
fetch_user_defined_function | SELECT | database_name, nameWithArgs, schema_name, endpoint | - | Fetch a UDF |
list_user_defined_functions | SELECT | database_name, schema_name, endpoint | like | List UDFs |
create_user_defined_function | INSERT | database_name, schema_name, data__arguments, data__language_config, data__name, data__return_type, endpoint | createMode , copyGrants | Create a UDF |
delete_user_defined_function | DELETE | database_name, nameWithArgs, schema_name, endpoint | ifExists | Delete a UDF |
rename_user_defined_function | EXEC | database_name, nameWithArgs, schema_name, targetDatabase, targetName, targetSchema, endpoint | ifExists | Rename a UDF |
Optional Parameter Details
Name | Description | Type | Default |
---|---|---|---|
copyGrants | Query parameter to enable copy grants when creating the object. | boolean | false |
createMode | Query 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. | string | errorIfExists |
ifExists | Query 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. | boolean | false |
like | Query parameter to filter the command output by resource name. Uses case-insensitive pattern matching, with support for SQL wildcard characters. | string | - |
SELECT
examples
- list_user_defined_functions
- fetch_user_defined_function
List UDFs
SELECT
name,
arguments,
body,
comment,
created_on,
database_name,
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,
schema_name,
valid_for_clustering
FROM snowflake.user_defined_function.user_defined_functions
WHERE database_name = '{{ database_name }}'
AND schema_name = '{{ schema_name }}'
AND endpoint = '{{ endpoint }}';
Fetch a UDF
SELECT
name,
arguments,
body,
comment,
created_on,
database_name,
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,
schema_name,
valid_for_clustering
FROM snowflake.user_defined_function.user_defined_functions
WHERE database_name = '{{ database_name }}'
AND nameWithArgs = '{{ nameWithArgs }}'
AND schema_name = '{{ schema_name }}'
AND endpoint = '{{ endpoint }}';
INSERT
example
Create a UDF
- Required Properties
- All Properties
- Manifest
/*+ create */
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
)
SELECT
'{{ name }}',
{{ is_temporary }},
{{ is_aggregate }},
{{ is_memoizable }},
{{ is_secure }},
'{{ arguments }}',
'{{ return_type }}',
'{{ language_config }}',
'{{ comment }}',
'{{ body }}',
'{{ database_name }}',
'{{ schema_name }}',
'{{ endpoint }}'
;
/*+ create */
INSERT INTO snowflake.user_defined_function.user_defined_functions (
data__name,
data__arguments,
data__return_type,
data__language_config,
database_name,
schema_name,
endpoint
)
SELECT
'{{ name }}',
'{{ arguments }}',
'{{ return_type }}',
'{{ language_config }}',
'{{ database_name }}',
'{{ schema_name }}',
'{{ endpoint }}'
;
# Description fields below are for documentation purposes only and are not required in the manifest
- name: user_defined_functions
props:
- name: database_name
value: string
description: Required parameter for the user_defined_functions resource.
- name: schema_name
value: string
description: Required parameter for the user_defined_functions resource.
- name: endpoint
value: string
description: Required parameter for the user_defined_functions resource.
- name: name
value: string
description: >-
The name of the UDF (Required parameter for the user_defined_functions
resource.)
- name: is_temporary
value: boolean
description: Specifies whether the UDF is temporary or not
- name: is_aggregate
value: boolean
description: >-
Specifies whether the UDF is an aggregate function. Applicable only for
Python language type
- name: is_memoizable
value: boolean
description: >-
Indicates whether the function is memoizable. Applicable only for Python
language type.
- name: is_secure
value: boolean
description: Specifies whether the function/procedure is secure or not
- name: arguments
value:
- name: name
value: string
description: Argument name
- name: datatype
value: string
description: >-
Argument data type (valid values: 'ARRAY', 'BIGINT', 'BINARY',
'BOOLEAN', 'BYTEINT', 'CHAR', 'CHARACTER', 'DATE', 'DATETIME',
'DECIMAL', 'DOUBLE', 'DOUBLE PRECISION', 'FLOAT', 'FLOAT4',
'FLOAT8', 'GEOGRAPHY', 'GEOMETRY', 'INT', 'INTEGER', 'NUMBER',
'NUMERIC', 'OBJECT', 'REAL', 'STRING', 'SMALLINT', 'TEXT', 'TIME',
'TIMESTAMP_LTZ', 'TIMESTAMP_NTZ', 'TIMESTAMP_TZ', 'TINYINT',
'VARBINARY', 'VARCHAR', 'VARIANT', 'VECTOR')
- name: default_value
value: string
description: Default value of the argument
description: >-
List of arguments for the function/procedure (Required parameter for the
user_defined_functions resource.)
- name: return_type
value:
type: string
description: Required parameter for the user_defined_functions resource.
- name: language_config
value:
language: string
called_on_null_input: boolean
is_volatile: boolean
description: Required parameter for the user_defined_functions resource.
- name: comment
value: string
description: Specifies a comment for the function/procedure
- name: body
value: string
description: Function/procedure definition
DELETE
example
Delete a UDF
/*+ delete */
DELETE FROM snowflake.user_defined_function.user_defined_functions
WHERE database_name = '{{ database_name }}'
AND nameWithArgs = '{{ nameWithArgs }}'
AND schema_name = '{{ schema_name }}'
AND endpoint = '{{ endpoint }}';