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 create, update, delete and fetch information about tables, as well as perform certain actions on them.
Attributes
- database¶
- fully_qualified_name¶
- root¶
Methods
- create_or_alter(table: Table) None ¶
Create or alter a table.
- Parameters:
table (Table) – The
Table
object, 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.create
for 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
PollingOperation
for more information on asynchronous execution and the return type.
- create_or_update(table: Table) None ¶
Create or update a table.
- Parameters:
table (Table) – The
Table
object, 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_update(my_table_def)
See
TableCollection.create
for 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.
The create_or_update method is deprecated; use create_or_alter instead.
- delete() None ¶
Delete the table.
Examples
Deleting a table using its reference:
>>> table_ref.delete() The `delete` method is deprecated; use `drop` instead.
- 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
PollingOperation
for 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
PollingOperation
for 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
PollingOperation
for 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
PollingOperation
for 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_table
withother_table
in 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
PollingOperation
for more information on asynchronous execution and the return type.
- undelete() None ¶
Undelete the previously deleted table.
Examples
Undeleting a table using its reference:
>>> table_ref.delete() >>> table_ref.undelete() The `undelete` method is deprecated; use `undrop` instead.
- 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
PollingOperation
for more information on asynchronous execution and the return type.