snowflake.core.table.TableResource¶
- class snowflake.core.table.TableResource(name: str, collection: TableCollection)¶
Bases:
SchemaObjectReferenceMixin[TableCollection]Represents a reference to a Snowflake table.
With this table reference, you can fetch information about a table, as well as perform certain actions on it.
Attributes
- database¶
The DatabaseResource this reference belongs to.
- fully_qualified_name¶
Return the fully qualified name of the object this reference points to.
- root¶
The Root object this reference belongs to.
Methods
- create_or_alter(table: Table) None¶
Create or alter a table.
- Parameters:
table (Table) – The
Tableobject, including theTable’s 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 are optional.
Examples
Creating a new table:
>>> my_schema.table["my_table"].create_or_alter(my_table_def)
See
TableCollection.createfor more examples.Notes
- Not currently implemented:
Row access policy
Column masking policy
Search optimization
Tags
Stage file format and copy options
Foreign keys.
Rename the table.
If the name and table’s name don’t match, an error will be thrown.
Rename or drop a column.
New columns can only be added to the back of the column list.
- create_or_alter_async(table: Table) PollingOperation[None]¶
An asynchronous version of
create_or_alter().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- create_or_update(table: Table) None¶
The
create_or_update()method is deprecated; usecreate_or_alter()instead.Create or update a table.
- table: Table
The
Tableobject, including theTable’s 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 are optional.
Creating a new table:
>>> my_schema.table["my_table"].create_or_update(my_table_def)
See
TableCollection.createfor more examples.- Not currently implemented:
Row access policy
Column masking policy
Search optimization
Tags
Stage file format and copy options
Foreign keys.
Rename the table.
If the name and table’s name don’t match, an error will be thrown.
Rename or drop a column.
New columns can only be added to the back of the column list.
- delete() None¶
The
delete()method is deprecated; usedrop()instead.Delete the table.
Deleting a table using its reference:
>>> table_ref.delete()
- drop(if_exists: bool | None = None) None¶
Drop the table.
- Parameters:
if_exists (bool, optional) – Check the existence of this table before suspending it. Default is
None, which is equivalent toFalse.
Examples
Dropping a table using its reference:
>>> table_ref.drop()
- drop_async(if_exists: bool | None = None) PollingOperation[None]¶
An asynchronous version of
drop().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- fetch() Table¶
Fetch the details of a table.
Examples
Fetching a reference to a table to print its comment:
>>> table_ref = my_schema.tables["my_table"].fetch() >>> print(table_ref.comment)
Notes
Inline constraints will become Outofline constraints because Snowflake database doesn’t tell whether a constraint is inline or out of line from Snowflake database.
- fetch_async() PollingOperation[Table]¶
An asynchronous version of
fetch().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- get_tags(with_lineage: bool | None = None) dict[TagResource, TagValue]¶
Get the tag assignments for a table.
Returns all tags assigned to a table. This operation requires an active warehouse.
- Parameters:
with_lineage (bool, optional) – Parameter that specifies whether tag assignments inherited by the object from its ancestors in securable object hierarchy should be returned as well: - true: All tags assigned to this object should be returned, inheritance included. - false: Only tags explicitly assigned to this object should be returned.
- get_tags_async(with_lineage: bool | None = None) PollingOperation[dict[TagResource, TagValue]]¶
An asynchronous version of
get_tags().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- resume_recluster(if_exists: bool | None = None) None¶
Resume reclustering for this table.
- Parameters:
if_exists (bool, optional) – Check the existence of this table before resuming its recluster. Default is
None, which is equivalent toFalse.
Examples
Resume reclustering for a table using its reference`:
>>> my_schema.tables["my_table"].resume_recluster()
- resume_recluster_async(if_exists: bool | None = None) PollingOperation[None]¶
An asynchronous version of
resume_recluster().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- set_tags(tags: dict[TagResource, TagValue], if_exists: bool | None = None) None¶
Set tags on a table.
- Parameters:
tags (dict[TagResource, TagValue]) – (required)
if_exists (bool) – Parameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn’t exist.
- set_tags_async(tags: dict[TagResource, TagValue], if_exists: bool | None = None) PollingOperation[None]¶
An asynchronous version of
set_tags().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- suspend_recluster(if_exists: bool | None = None) None¶
Suspend reclustering for this table.
- Parameters:
if_exists (bool, optional) – Check the existence of this table before suspending its recluster. Default is
None, which is equivalent toFalse.
Examples
Suspending reclustering for a table using its reference:
>>> my_schema.tables["my_table"].suspend_recluster()
- suspend_recluster_async(if_exists: bool | None = None) PollingOperation[None]¶
An asynchronous version of
suspend_recluster().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- swap_with(to_swap_table_name: str, if_exists: bool | None = None, target_database: str | None = None, target_schema: str | None = None) None¶
Swap the name with another table.
- Parameters:
to_swap_table_name (str) – The name of the table we should swap the current table with.
if_exists (bool, optional) – Check the existence of this table before swapping its name. Default is
None, which is equivalent toFalse.target_database (str, optional) – The name of the database where the table to be swapped with exists. The default is
None, which means the current database.target_schema (str, optional) – The name of the schema where the table to be swapped with exists. The default is
None, which means the current schema.
Examples
Swapping
my_tablewithother_tablein the same schema:>>> my_table = my_schema.tables["my_table"].swap("other_table")
- swap_with_async(to_swap_table_name: str, if_exists: bool | None = None, target_database: str | None = None, target_schema: str | None = None) PollingOperation[None]¶
An asynchronous version of
swap_with().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- undelete() None¶
The
undelete()method is deprecated; useundrop()instead.Undelete the previously deleted table.
Undeleting a table using its reference:
>>> table_ref.delete() >>> table_ref.undelete()
- undrop() None¶
Undrop the previously dropped table.
Examples
Undropping a table using its reference:
>>> table_ref.drop() >>> table_ref.undrop()
- undrop_async() PollingOperation[None]¶
An asynchronous version of
undrop().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- unset_tags(tag_resources: set[TagResource], if_exists: bool | None = None) None¶
Unset tags from a table.
- Parameters:
tag_resources (set[TagResource]) – (required)
if_exists (bool) – Parameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn’t exist.
- unset_tags_async(tag_resources: set[TagResource], if_exists: bool | None = None) PollingOperation[None]¶
An asynchronous version of
unset_tags().Refer to
PollingOperationfor more information on asynchronous execution and the return type.