snowflake.core.dynamic_table.DynamicTableCollection¶
- 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¶
- root¶
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:
table (DynamicTable | DynamicTableClone | str) –
- The
DynamicTable
object, together with the dynamic table’s properties: name, target_lag, warehouse, query; columns, refresh_mode, initialize, cluster_by, comment are optional.
- The
The
DynamicTableClone
object, when it’s used with clone_table.The table name.
clone_table (Clone, optional) – The source table to clone from.
copy_grants (bool, optional) – Whether to enable copy grants when creating the object. Default is
False
.mode (CreateMode, optional) –
One of the following enum values.
CreateMode.error_if_exists
: Throw ansnowflake.core.exceptions.ConflictError
if the dynamic table already exists in Snowflake. Equivalent to SQLcreate dynamic table <name> ...
.CreateMode.or_replace
: Replace if the dynamic table already exists in Snowflake. Equivalent to SQLcreate or replace dynamic table <name> ...
.CreateMode.if_not_exists
: Do nothing if the dynamic table already exists in Snowflake. Equivalent to SQLcreate dynamic table <name> if not exists...
Default is
CreateMode.error_if_exists
.
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, ... )
- 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:
like (str, optional) – A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).
starts_with (str, optional) – String used to filter the command output based on the string of characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.
show_limit (int, optional) – Limit of the maximum number of rows returned by iter(). The default is
None
, which behaves equivalently to show_limit=10000. This value must be between1
and10000
.from_name (str, optional) – Fetch rows only following the first row whose object name matches the specified string. This is case-sensitive and does not have to be the full name.
deep (bool, optional) – Optionally includes dependency information of the dynamic table. Default is
None
, which is equivalent toFalse
.
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)
- keys() KeysView[str] ¶
- values() ValuesView[T] ¶