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:
- procedure (Procedure) – The
Procedure
object, together with theProcedure
’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.ConflictErrorif the procedure already exists in Snowflake. Equivalent to SQLcreate procedure <name> ...
.CreateMode.or_replace
: Replace if the procedure already exists in Snowflake. Equivalent to SQLcreate or replace procedure <name> ...
.CreateMode.if_not_exists
: Do nothing if the procedure already exists in Snowflake. Equivalent to SQLcreate procedure <name> if not exists...
Default value isCreateMode.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)
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]¶