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]ΒΆ