snowflake.core.function.FunctionCollection

class snowflake.core.function.FunctionCollection(schema: SchemaResource)

Bases: SchemaObjectCollectionParent[FunctionResource]

Represents the collection operations on the Snowflake Function resource.

With this collection, you can create, iterate through, and search for function that you have access to in the current context.

Examples

Creating a function instance:

>>> functions = root.databases["my_db"].schemas["my_schema"].functions
>>> new_function = Function(
...     name="foo",
...     returns="NUMBER",
...     arguments=[FunctionArgument(datatype="NUMBER")],
...     service="python",
...     endpoint="https://example.com",
...     path="example.py"
... )
>>> functions.create(new_function)
Copy

Attributes

database
root

Methods

create(function: Function, mode: CreateMode = CreateMode.error_if_exists) FunctionResource

Create a function in Snowflake.

Parameters:
  • function (Function) – The Function object, together with Function’s properties: name, returns, arguments, service, endpoint, path; max_batch_rows is optional

  • mode (CreateMode, optional) –

    One of the following enum values.

    CreateMode.error_if_exists: Throw an snowflake.core.exceptions.ConflictError if the function already exists in Snowflake. Equivalent to SQL create function <name> ....

    CreateMode.or_replace: Replace if the function already exists in Snowflake. Equivalent to SQL create or replace function <name> ....

    CreateMode.if_not_exists: Do nothing if the function already exists in Snowflake. Equivalent to SQL create function <name> if not exists...

    Default is CreateMode.error_if_exists.

Examples

Creating a function, replacing any existing function with the same name:

>>> functions = root.databases["my_db"].schemas["my_schema"].functions
>>> new_function = Function(
...     name="foo",
...     returns="NUMBER",
...     arguments=[FunctionArgument(datatype="NUMBER")],
...     service="python",
...     endpoint="https://example.com",
...     path="example.py"
... )
>>> functions.create(new_function, mode=CreateMode.or_replace)
Copy
items() ItemsView[str, T]
iter(*, like: str | None = None) Iterator[Function]

Iterate through Function objects from Snowflake, filtering on any optional ‘like’ pattern.

Parameters:

like (str, optional) – A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).

Examples

Showing all functions that you have access to see:

>>> functions = function_collection.iter()
Copy

Showing information of the exact function you want to see:

>>> functions = function_collection.iter(like="your-function-name")
Copy

Showing functions starting with ‘your-function-name-‘:

>>> functions = function_collection.iter(like="your-function-name-%")
Copy

Using a for loop to retrieve information from iterator:

>>> for function in functions:
...     print(function.name)
Copy
keys() KeysView[str]
values() ValuesView[T]
Language: English