Skip to main content

functions

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

Overview

Namefunctions
TypeResource
Idsnowflake.function.functions

Fields

The following fields are returned by SELECT queries:

A Snowflake function

NameDatatypeDescription
namestringSpecifies the name for the function, must be unique for the schema in which the function is created
argumentsarray
bodystringFunction's body.
created_onstring (date-time)Date and time when the function was created.
function_typestring (default: service-function)
languagestringFunction's language.
max_batch_rowsintegerSpecifies the max rows for batch operation.
returnsstringSpecifies the type for the function return value. (default: TEXT)
signaturestringFunction's arguments.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
list_functionsselectdatabase_name, schema_name, endpointlikeLists the user functions under the database and schema.
fetch_functionselectdatabase_name, schema_name, nameWithArgs, endpointFetch a Function using the describe command output.
create_functioninsertdatabase_name, schema_name, endpointcreateModeCreate a function.
delete_functiondeletedatabase_name, schema_name, nameWithArgs, endpointifExistsDelete a function with the given name and args.
execute_functionexecdatabase_name, schema_name, name, endpointExecute 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.

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)
namestringIdentifier (i.e. name) for the resource.
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.
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

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.function.functions
WHERE database_name = '{{ database_name }}' -- required
AND schema_name = '{{ schema_name }}' -- required
AND endpoint = '{{ endpoint }}' -- required
AND like = '{{ like }}';

INSERT examples

Create a function.

INSERT INTO snowflake.function.functions (
data__function_type,
data__name,
data__arguments,
data__returns,
data__max_batch_rows,
data__created_on,
data__signature,
data__language,
data__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 }}'
;

DELETE examples

Delete a function with the given name and args.

DELETE FROM snowflake.function.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

Execute a Function.

EXEC snowflake.function.functions.execute_function 
@database_name='{{ database_name }}' --required,
@schema_name='{{ schema_name }}' --required,
@name='{{ name }}' --required,
@endpoint='{{ endpoint }}' --required;