snowflake.core.table.TableCollectionΒΆ
- class snowflake.core.table.TableCollection(schema: SchemaResource)ΒΆ
- Bases: - SchemaObjectCollectionParent[- TableResource]- Represents the collection operations on the Snowflake Table resource. - With this collection, you can create, iterate through, and search for tables that you have access to in the current context. - Examples - Creating a table instance: - >>> tables = root.databases["my_db"].schemas["my_schema"].tables >>> new_table = Table( ... name="accounts", ... columns=[ ... TableColumn( ... name="id", ... datatype="int", ... nullable=False, ... autoincrement=True, ... autoincrement_start=0, ... autoincrement_increment=1, ... ), ... TableColumn(name="created_on", datatype="timestamp_tz", nullable=False), ... TableColumn(name="email", datatype="string", nullable=False), ... TableColumn(name="password_hash", datatype="string", nullable=False), ... ], ... ) >>> tables.create(new_tables) - Attributes - databaseΒΆ
- The DatabaseResource this collection belongs to. 
 - rootΒΆ
- The Root object this collection belongs to. 
 - Methods - create(table: Table | str, *, as_select: str | None = None, template: str | None = None, like_table: str | None = None, clone_table: str | Clone | None = None, copy_grants: bool | None = False, mode: CreateMode = CreateMode.error_if_exists) TableResourceΒΆ
- Create a table in Snowflake. - Parameters:
- table (Table) β The - Tableobject, together with the- Tableβs properties, object parameters, columns, and constraints. It can either be a table name or a- Tableobject when itβs used together with as_select, template, like_table, clone_table. It must be a- Tablewhen itβs not used with these clauses.- Tablehas the following properties: name; kind, cluster_by, enable_schema_evolution, change_tracking, data_retention_time_in_days, max_data_extension_time_in_days, default_ddl_collation, columns, constraints, comment, database_name, schema_name are optional.
- as_select (str, optional) β Creates a table from a select statement. 
- template (str, optional) β Create a table using the templates specified in staged files. 
- like_table (str, optional) β Create a new table like the specified one, but empty. 
- clone_table (str or Clone, optional) β Create a new table by cloning the specified table. 
- copy_grants (bool, optional) β Copy grants when clone_table is provided. 
- mode (CreateMode, optional) β - One of the following strings. - CreateMode.error_if_exists: Throw an- snowflake.core.exceptions.ConflictErrorif the table already exists in Snowflake. Equivalent to SQL- create table <name> ....- CreateMode.or_replace: Replace if the task already exists in Snowflake. Equivalent to SQL- create or replace table <name> ....- CreateMode.if_not_exists: Do nothing if the task already exists in Snowflake. Equivalent to SQL- create table <name> if not exists...- Default value is - CreateMode.error_if_exists.
 
 - Examples - Creating a table instance: - >>> tables = root.databases["my_db"].schemas["my_schema"].tables >>> new_table = Table( ... name="events", ... columns=[ ... TableColumn( ... name="id", ... datatype="int", ... nullable=False, ... autoincrement=True, ... autoincrement_start=0, ... autoincrement_increment=1, ... ), ... TableColumn(name="category", datatype="string"), ... TableColumn(name="event", datatype="string"), ... ], ... comment="store events/logs in here", ... ) >>> tables.create(new_tables) - Cloning a Table instance: - >>> tables = root.databases["my_db"].schemas["my_schema"].tables >>> tables.create("new_table", clone_table="original_table_name") - Cloning a Table instance in a different database and schema: - >>> tables = root.databases["my_db"].schemas["my_schema"].tables >>> tables.create("new_table", clone_table="database_name.schema_name.original_table_name") - Notes - Not currently implemented:
- Row access policy 
- Column masking policy 
- Search optimization 
- Tags 
- Stage file format and copy options 
 
 
 - create_async(table: Table | str, *, as_select: str | None = None, template: str | None = None, like_table: str | None = None, clone_table: str | Clone | None = None, copy_grants: bool | None = False, mode: CreateMode = CreateMode.error_if_exists) PollingOperation[TableResource]ΒΆ
- An asynchronous version of - iter().- Refer to - PollingOperationfor 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, history: bool = False, deep: bool = False) Iterator[Table]ΒΆ
- Iterate through - Tableobjects 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. 
- 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 between- 1and- 10000.
- 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. 
- history (bool, optional) β Include dropped tables that have not yet been purged yet. 
- deep (bool, optional) β Fetch the sub-resources columns and constraints of every table if itβs - True. Default- False.
 
 - Examples - Showing all tables that you have access to see in a schema: - >>> tables = my_schema.tables.iter() - Showing information of the exact table you want to see: - >>> tables = my_schema.tables.iter(like="my-table-name") - Showing tables starting with βmy-table-name-β: - >>> tables = my_schema.tables.iter(like="my-table-name-%") - Using a for loop to retrieve information from iterator: - >>> for table in table: >>> print(table.name, table.kind) 
 - iter_async(*, like: str | None = None, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None, history: bool = False, deep: bool = False) PollingOperation[Iterator[Table]]ΒΆ
- An asynchronous version of - iter().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - keys() KeysView[str]ΒΆ
 - update_reference(old_name: str, new_name: str, resource: T) NoneΒΆ
- Update the collection with a new item. 
 - values() ValuesView[T]ΒΆ