Skip to main content

tables

Creates, updates, deletes, gets or lists a tables resource.

Overview

Nametables
TypeResource
Idsnowflake.table.tables

Fields

NameDatatypeDescription
namestringSpecifies the name for the table, must be unique for the schema in which the table is created
automatic_clusteringbooleanIf Automatic Clustering is enabled for your account, specifies whether it is explicitly enabled or disabled for the table.
budgetstringName of the budget if the object is monitored by a budget
bytesintegerNumber of bytes that will be scanned if the entire table is scanned in a query. Note that this number may be different than the number of actual physical bytes stored on-disk for the table
change_trackingbooleanChange tracking is enabled or disabled
cluster_byarraySpecifies one or more columns or column expressions in the table as the clustering key
columnsarray
commentstringComment for the table
constraintsarray
created_onstringDate and time when the table was created.
data_retention_time_in_daysintegerSpecifies the retention period for the table so that Time Travel actions SELECT, CLONE, UNDROP can be performed on historical data in the table
database_namestringDatabase in which the table is stored
default_ddl_collationstringSpecifies a default collation specification for the columns in the table, including columns added to the table in the future
dropped_onstringDate and time when the table was dropped
enable_schema_evolutionbooleanTable has schema evolution enabled or disabled
kindstringTable type - permanent, transient, or temporary
max_data_extension_time_in_daysintegerSpecifies the retention period for the table so that Time Travel actions SELECT, CLONE, UNDROP can be performed on historical data in the table
ownerstringRole that owns the table
owner_role_typestringThe type of role that owns the object.
rowsintegerNumber of rows in the table. Returns NULL for external tables.
schema_namestringSchema in which the table is stored
search_optimizationbooleanIf ON, the table has the search optimization service enabled
search_optimization_bytesintegerNumber of additional bytes of storage that the search optimization service consumes for this table
search_optimization_progressintegerPercentage of the table that has been optimized for search.
table_typestringType of the table

Methods

NameAccessible byRequired ParamsOptional ParamsDescription
fetch_tableSELECTdatabase_name, name, schema_name, endpoint-Fetch a Table using the describe command output.
list_tablesSELECTdatabase_name, schema_name, endpointlike, startsWith, showLimit, fromName, history, deepLists the tables under the database and schema.
create_tableINSERTdatabase_name, schema_name, data__name, endpointcreateMode, copyGrantsCreate a table.
delete_tableDELETEdatabase_name, name, schema_name, endpointifExistsDelete a table with the given name.
create_or_alter_tableREPLACEdatabase_name, name, schema_name, data__name, endpoint-Create a (or alter an existing) table. Even if the operation is just an alter, the full property set must be provided.
clone_tableEXECdatabase_name, name, schema_name, endpointcreateMode, copyGrants, targetDatabase, targetSchemaCreate a new table by cloning from the specified resource
create_table_as_selectEXECdatabase_name, query, schema_name, endpointcreateMode, copyGrantsCreate a table as select.
create_table_as_select_deprecatedEXECdatabase_name, name, query, schema_name, data__name, endpointcreateMode, copyGrantsCreate a table as select.
create_table_likeEXECdatabase_name, name, schema_name, endpointcreateMode, copyGrantsCreate a new table like the specified resource, but empty
create_table_like_deprecatedEXECdatabase_name, name, newTableName, schema_name, endpointcreateMode, copyGrantsCreate a new table like the specified resource, but empty
create_table_using_templateEXECdatabase_name, query, schema_name, endpointcreateMode, copyGrantsCreate a table using template.
create_table_using_template_deprecatedEXECdatabase_name, name, query, schema_name, endpointcreateMode, copyGrantsCreate a table using template.
resume_recluster_tableEXECdatabase_name, name, schema_name, endpointifExistsResume recluster of a table
resume_recluster_table_deprecatedEXECdatabase_name, name, schema_name, endpointifExistsResume recluster of a table
suspend_recluster_tableEXECdatabase_name, name, schema_name, endpointifExistsSuspend recluster of a table
suspend_recluster_table_deprecatedEXECdatabase_name, name, schema_name, endpointifExistsSuspend recluster of a table
swap_with_tableEXECdatabase_name, name, schema_name, targetName, endpointifExists, targetDatabase, targetSchemaSwap with another table
swap_with_table_deprecatedEXECdatabase_name, name, schema_name, targetTableName, endpointifExistsSwap with another table
undrop_tableEXECdatabase_name, name, schema_name, endpoint-Undrop specified table

Optional Parameter Details
NameDescriptionTypeDefault
copyGrantsQuery parameter to enable copy grants when creating the object.booleanfalse
createModeQuery parameter allowing support for different modes of resource creation. Possible values include: - errorIfExists: Throws an error if you try to create a resource that already exists. - orReplace: Automatically replaces the existing resource with the current one. - ifNotExists: Creates a new resource when an alter is requested for a non-existent resource.stringerrorIfExists
deepOptionally includes dependency information of the table.boolean-
fromNameQuery parameter to enable fetching rows only following the first row whose object name matches the specified string. Case-sensitive and does not have to be the full name.string-
historyOptionally includes dropped tables that have not yet been purged.boolean-
ifExistsQuery 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.booleanfalse
likeQuery parameter to filter the command output by resource name. Uses case-insensitive pattern matching, with support for SQL wildcard characters.string-
showLimitQuery parameter to limit the maximum number of rows returned by a command.integer-
startsWithQuery parameter 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.string-
targetDatabaseDatabase of the newly created table. Defaults to the source table's database.string-
targetSchemaSchema of the newly created table. Defaults to the source table's schema.string-

SELECT examples

Lists the tables under the database and schema.

SELECT
name,
automatic_clustering,
budget,
bytes,
change_tracking,
cluster_by,
columns,
comment,
constraints,
created_on,
data_retention_time_in_days,
database_name,
default_ddl_collation,
dropped_on,
enable_schema_evolution,
kind,
max_data_extension_time_in_days,
owner,
owner_role_type,
rows,
schema_name,
search_optimization,
search_optimization_bytes,
search_optimization_progress,
table_type
FROM snowflake.table.tables
WHERE database_name = '{{ database_name }}'
AND schema_name = '{{ schema_name }}'
AND endpoint = '{{ endpoint }}';

INSERT example

Create a table.

/*+ create */
INSERT INTO snowflake.table.tables (
data__name,
data__kind,
data__cluster_by,
data__enable_schema_evolution,
data__change_tracking,
data__data_retention_time_in_days,
data__max_data_extension_time_in_days,
data__default_ddl_collation,
data__columns,
data__constraints,
data__comment,
database_name,
schema_name,
endpoint
)
SELECT
'{{ 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 }}',
'{{ endpoint }}'
;

REPLACE example

Create a (or alter an existing) table. Even if the operation is just an alter, the full property set must be provided.

/*+ update */
REPLACE snowflake.table.tables
SET
name = '{{ name }}',
kind = '{{ kind }}',
cluster_by = '{{ cluster_by }}',
enable_schema_evolution = {{ enable_schema_evolution }},
change_tracking = {{ change_tracking }},
data_retention_time_in_days = {{ data_retention_time_in_days }},
max_data_extension_time_in_days = {{ max_data_extension_time_in_days }},
default_ddl_collation = '{{ default_ddl_collation }}',
columns = '{{ columns }}',
constraints = '{{ constraints }}',
comment = '{{ comment }}'
WHERE
database_name = '{{ database_name }}'
AND name = '{{ name }}'
AND schema_name = '{{ schema_name }}'
AND data__name = '{{ data__name }}'
AND endpoint = '{{ endpoint }}';

DELETE example

Delete a table with the given name.

/*+ delete */
DELETE FROM snowflake.table.tables
WHERE database_name = '{{ database_name }}'
AND name = '{{ name }}'
AND schema_name = '{{ schema_name }}'
AND endpoint = '{{ endpoint }}';