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_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() None ¶
Drop the table.
Examples
Dropping a table using its reference:
>>> table_ref.drop()
- 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.
- resume_recluster() None ¶
Resume reclustering for this table.
Examples
Resume reclustering for a table using its reference`:
>>> my_schema.tables["my_table"].resume_recluster()
- suspend_recluster() None ¶
Suspend reclustering for this table.
Examples
Suspending reclustering for a table using its reference:
>>> my_schema.tables["my_table"].suspend_recluster()
- swap_with(to_swap_table_name: str) 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.
Examples
Swapping
my_table
withother_table
in the same schema:>>> my_table = my_schema.tables["my_table"].swap("other_table")
- 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()