snowflake.core.procedure.ProcedureCollection | Snowflake Documentation (original) (raw)

class snowflake.core.procedure.ProcedureCollection(schema: SchemaResource)

Bases: SchemaObjectCollectionParent[ProcedureResource]

Represents the collection operations on the Snowflake Procedure resource.

With this collection, you can create, iterate through, and fetch procedures that you have access to in the current context.

Examples

Creating a procedure instance:

procedure = Procedure( ... name="sql_proc_table_func", ... arguments=[Argument(name="id", datatype="VARCHAR")], ... return_type=ReturnTable( ... column_list=[ ... ColumnType(name="id", datatype="NUMBER"), ... ColumnType(name="price", datatype="NUMBER"), ... ] ... ), ... language_config=SQLFunction(), ... body=" ... DECLARE ... res RESULTSET DEFAULT (SELECT * FROM invoices WHERE id = :id); ... BEGIN ... RETURN TABLE(res); ... END; ... ", ... ) procedures = root.databases["my_db"].schemas["my_schema"].procedures procedures.create(procedure)

Attributes

database

The DatabaseResource this collection belongs to.

root

The Root object this collection belongs to.

Methods

create(procedure: Procedure, mode: CreateMode = CreateMode.error_if_exists, copy_grants: bool = False) → ProcedureResource

Create a procedure in Snowflake.

Parameters:

Examples

Creating a procedure, replacing an existing procedure with the same name:

procedure = Procedure( ... name="my_procedure", ... arguments=[], ... return_type=ReturnDataType(datatype="FLOAT"), ... language_config=JavaScriptFunction(), ... body="return 3.14;" ... ) procedures = root.databases["my_db"].schemas["my_schema"].procedures procedures.create(procedure, mode=CreateMode.or_replace)

create_async(procedure: Procedure, mode: CreateMode = CreateMode.error_if_exists, copy_grants: bool = False) → PollingOperation[ProcedureResource]

An asynchronous version of create().

Refer to PollingOperation for more information on asynchronous execution and the return type.

items() → ItemsView[str, T]

iter(*, like: str | None = None) → Iterator[Procedure]

Iterate through Procedure 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 procedures that you have access to see:

procedures = root.databases["my_db"].schemas["my_schema"].procedures.iter()

Showing information of the exact procedure you want to see:

procedures = root.databases["my_db"].schemas["my_schema"].procedures.iter(like="your-procedure-name")

Showing procedures starting with ‘your-procedure-name-‘:

procedures = root.databases["my_db"].schemas["my_schema"].procedures.iter(like="your-procedure-name-%")

Using a for loop to retrieve information from iterator:

for procedure in procedures: ... print(procedure.name)

iter_async(*, like: str | None = None) → PollingOperation[Iterator[Procedure]]

An asynchronous version of iter().

Refer to PollingOperation for more information on asynchronous execution and the return type.

keys() → KeysView[str]

values() → ValuesView[T]