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

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 Table object, including the Table’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)
Copy

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

The create_or_update() method is deprecated; use create_or_alter() instead.

Create or update a table.

table: Table

The Table object, including the Table’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)
Copy

See TableCollection.create for 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; use drop() instead.

Delete the table.

Deleting a table using its reference:

>>> table_ref.delete()
Copy
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 to False.

Examples

Dropping a table using its reference:

>>> table_ref.drop()
Copy
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)
Copy

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 to False.

Examples

Resume reclustering for a table using its reference`:

>>> my_schema.tables["my_table"].resume_recluster()
Copy
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 to False.

Examples

Suspending reclustering for a table using its reference:

>>> my_schema.tables["my_table"].suspend_recluster()
Copy
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 to False.

  • 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 with other_table in the same schema:

>>> my_table = my_schema.tables["my_table"].swap("other_table")
Copy
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

The undelete() method is deprecated; use undrop() instead.

Undelete the previously deleted table.

Undeleting a table using its reference:

>>> table_ref.delete()
>>> table_ref.undelete()
Copy
undrop() None

Undrop the previously dropped table.

Examples

Undropping a table using its reference:

>>> table_ref.drop()
>>> table_ref.undrop()
Copy
undrop_async() PollingOperation[None]

An asynchronous version of undrop().

Refer to PollingOperation for more information on asynchronous execution and the return type.

Language: English