snowflake.core.procedure.ProcedureCollection

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)
Copy

Attributes

database
root

Methods

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

Create a procedure in Snowflake.

Parameters:
  • procedure (Procedure) – The Procedure object, together with the Procedure’s properties: name, arguments, return_type, language_config; secure, runtime_version, packages, imports, handler, external_access_integrations, secrets, called_on_null_input, return_type nullable, comment, execute_as, body are optional.

  • mode (CreateMode, optional) –

    One of the below enum values.

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

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

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

    Default value is CreateMode.error_if_exists.

  • copy_grants (bool, optional) – Whether to enable copy grants when creating the object. Default is False.

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)
Copy
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()
Copy

Showing information of the exact procedure you want to see:

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

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

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

Using a for loop to retrieve information from iterator:

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