snowflake.core.dynamic_table.DynamicTableCollection | Snowflake Documentation (original) (raw)

class snowflake.core.dynamic_table.DynamicTableCollection(schema: SchemaResource)

Bases: SchemaObjectCollectionParent[DynamicTableResource]

Represents the collection operations on the Snowflake Dynamic Table resource.

With this collection, you can create, iterate through, and search for dynamic tables that you have access to in the current context.

Examples

Creating a dynamic table instance:

dynamic_tables = root.databases["my_db"].schemas["my_schema"].dynamic_tables dynamic_tables.create( ... DynamicTable( ... name="my_dynamic_table", ... columns=[ ... DynamicTableColumn(name="c1"), ... DynamicTableColumn(name='"cc2"', datatype="varchar"), ... ], ... warehouse=db_parameters["my_warehouse"], ... target_lag=UserDefinedLag(seconds=60), ... query="SELECT * FROM my_table", ... ), ... mode=CreateMode.error_if_exists, ... )

Attributes

database

The DatabaseResource this collection belongs to.

root

The Root object this collection belongs to.

Methods

create(table: DynamicTable | DynamicTableClone | str, *, clone_table: str | Clone | None = None, copy_grants: bool | None = False, mode: CreateMode = CreateMode.error_if_exists) → DynamicTableResource

Create a dynamic table.

Parameters:

Examples

Creating a dynamic table, replacing any existing dynamic table with the same name:

dynamic_tables = root.databases["my_db"].schemas["my_schema"].dynamic_tables dynamic_tables.create( ... DynamicTable( ... name="my_dynamic_table", ... columns=[ ... DynamicTableColumn(name="c1"), ... DynamicTableColumn(name='"cc2"', datatype="varchar"), ... ], ... warehouse=db_parameters["my_warehouse"], ... target_lag=UserDefinedLag(seconds=60), ... query="SELECT * FROM my_table", ... ), ... mode=CreateMode.error_if_exists, ... )

Creating a dynamic table by cloning an existing table:

dynamic_tables = root.databases["my_db"].schemas["my_schema"].dynamic_tables dynamic_tables.create( ... DynamicTableClone( ... name="my_dynamic_table", ... target_lag=UserDefinedLag(seconds=120), ... ), ... clone_table=Clone( ... source="my_source_dynamic_table", ... point_of_time=PointOfTimeOffset(reference="before", when="-1") ... ), ... copy_grants=True, ... )

Creating a dynamic table by cloning an existing table in a different database and schema:

dynamic_tables = root.databases["my_db"].schemas["my_schema"].dynamic_tables dynamic_tables.create( ... DynamicTableClone( ... name="my_dynamic_table", ... target_lag=UserDefinedLag(seconds=120), ... ), ... clone_table=Clone( ... source="database_of_source_table.schema_of_source_table.my_source_dynamic_table", ... point_of_time=PointOfTimeOffset(reference="before", when="-1") ... ), ... copy_grants=True, ... )

create_async(table: DynamicTable | DynamicTableClone | str, *, clone_table: str | Clone | None = None, copy_grants: bool | None = False, mode: CreateMode = CreateMode.error_if_exists) → PollingOperation[DynamicTableResource]

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, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None, deep: bool = False) → Iterator[DynamicTable]

Iterate through DynamicTable objects from Snowflake, filtering on any optional ‘like’ pattern.

Parameters:

Examples

Showing all dynamic tables that you have access to see:

dynamic_tables = dynamic_table_collection.iter()

Showing information of the exact dynamic table you want to see:

dynamic_tables = dynamic_table_collection.iter(like="your-dynamic-table-name")

Showing dynamic tables starting with ‘your-dynamic-table-name-‘:

dynamic_tables = dynamic_table_collection.iter(like="your-dynamic-table-name-%")

Using a for loop to retrieve information from iterator:

for dynamic_table in dynamic_tables: ... print(dynamic_table.name, dynamic_table.query)

iter_async(*, like: str | None = None, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None, deep: bool = False) → PollingOperation[Iterator[DynamicTable]]

An asynchronous version of iter().

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

keys() → KeysView[str]

values() → ValuesView[T]