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)
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 withFunction
’s properties: name, returns, arguments, service, endpoint, path; max_batch_rows is optionalmode (CreateMode, optional) –
One of the following enum values.
CreateMode.error_if_exists
: Throw ansnowflake.core.exceptions.ConflictError
if the function already exists in Snowflake. Equivalent to SQLcreate function <name> ...
.CreateMode.or_replace
: Replace if the function already exists in Snowflake. Equivalent to SQLcreate or replace function <name> ...
.CreateMode.if_not_exists
: Do nothing if the function already exists in Snowflake. Equivalent to SQLcreate 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)
- 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()
Showing information of the exact function you want to see:
>>> functions = function_collection.iter(like="your-function-name")
Showing functions starting with ‘your-function-name-‘:
>>> functions = function_collection.iter(like="your-function-name-%")
Using a for loop to retrieve information from iterator:
>>> for function in functions: ... print(function.name)
- keys() KeysView[str] ¶
- values() ValuesView[T] ¶