functions
Creates, updates, deletes, gets or lists a functions resource.
Overview
| Name | functions |
| Type | Resource |
| Id | snowflake.functions.functions |
Fields
The following fields are returned by SELECT queries:
- get
- list
successful
| Name | Datatype | Description |
|---|---|---|
name | string | Specifies the name for the function, must be unique for the schema in which the function is created |
arguments | array | |
body | string | Function's body. |
created_on | string (date-time) | Date and time when the function was created. |
function_type | string | (default: service-function) |
language | string | Function's language. |
max_batch_rows | integer | Specifies the max rows for batch operation. |
returns | string | Specifies the type for the function return value. (default: TEXT) |
signature | string | Function's arguments. |
A Snowflake function
| Name | Datatype | Description |
|---|---|---|
name | string | Specifies the name for the function, must be unique for the schema in which the function is created |
arguments | array | |
body | string | Function's body. |
created_on | string (date-time) | Date and time when the function was created. |
function_type | string | (default: service-function) |
language | string | Function's language. |
max_batch_rows | integer | Specifies the max rows for batch operation. |
returns | string | Specifies the type for the function return value. (default: TEXT) |
signature | string | Function's arguments. |
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 Function using the describe command output. | |
list | select | database_name, schema_name, endpoint | like | Lists the user functions under the database and schema. |
create | insert | database_name, schema_name, endpoint, name, arguments | createMode | Create a function. |
delete | delete | database_name, schema_name, name_with_args, endpoint | ifExists | Delete a function with the given name and args. |
execute | exec | database_name, schema_name, name, endpoint | Execute a Function. |
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 | string | Identifier (i.e. name) for the resource. |
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. |
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 Function using the describe command output.
SELECT
name,
arguments,
body,
created_on,
function_type,
language,
max_batch_rows,
returns,
signature
FROM snowflake.functions.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
;
Lists the user functions under the database and schema.
SELECT
name,
arguments,
body,
created_on,
function_type,
language,
max_batch_rows,
returns,
signature
FROM snowflake.functions.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 function.
INSERT INTO snowflake.functions.functions (
function_type,
name,
arguments,
returns,
max_batch_rows,
created_on,
signature,
language,
body,
database_name,
schema_name,
endpoint,
createMode
)
SELECT
'{{ function_type }}',
'{{ name }}' /* required */,
'{{ arguments }}' /* required */,
'{{ returns }}',
{{ max_batch_rows }},
'{{ created_on }}',
'{{ signature }}',
'{{ language }}',
'{{ body }}',
'{{ database_name }}',
'{{ schema_name }}',
'{{ endpoint }}',
'{{ createMode }}'
RETURNING
status
;
# Description fields are for documentation purposes
- name: functions
props:
- name: database_name
value: "{{ database_name }}"
description: Required parameter for the functions resource.
- name: schema_name
value: "{{ schema_name }}"
description: Required parameter for the functions resource.
- name: endpoint
value: "{{ endpoint }}"
description: Required parameter for the functions resource.
- name: function_type
value: "{{ function_type }}"
default: service-function
- name: name
value: "{{ name }}"
description: |
Specifies the name for the function, must be unique for the schema in which the function is created
- name: arguments
value:
- name: "{{ name }}"
datatype: "{{ datatype }}"
value: "{{ value }}"
- name: returns
value: "{{ returns }}"
description: |
Specifies the type for the function return value.
default: TEXT
- name: max_batch_rows
value: {{ max_batch_rows }}
description: |
Specifies the max rows for batch operation.
- name: created_on
value: "{{ created_on }}"
description: |
Date and time when the function was created.
- name: signature
value: "{{ signature }}"
description: |
Function's arguments.
- name: language
value: "{{ language }}"
description: |
Function's language.
- name: body
value: "{{ body }}"
description: |
Function's body.
- 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.
DELETE examples
- delete
Delete a function with the given name and args.
DELETE FROM snowflake.functions.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
- execute
Execute a Function.
EXEC snowflake.functions.functions.execute
@database_name='{{ database_name }}' --required,
@schema_name='{{ schema_name }}' --required,
@name='{{ name }}' --required,
@endpoint='{{ endpoint }}' --required
;