CREATE INTERACTIVE TABLE

statementpartialTables, views, streams, sequences

docs.snowflake.com ↗

Object: INTERACTIVE TABLE

Creates a new interactive table in the current/specified schema or replaces an existing table. Interactive tables are optimized for low-latency, interactive queries and provide the best performance when queried using interactive warehouses. Interactive tables support a more limited set of SQL operations than standard tables and are designed for high-concurrency, real-time query workloads such as dashboards and data-powered APIs. Note When you create an interactive table, you must define a CLUSTER BY clause on one or more columns that are used in the WHERE clauses for your most time-critical queries. You can also use the following CREATE INTERACTIVE TABLE variants: - Variant syntax: Static interactive table (creates a static interactive table populated from a query) - Variant syntax: Dynamic interactive table (creates a dynamic interactive table with automatic refresh) For the full CREATE TABLE syntax used for standard Snowflake tables, see CREATE TABLE. Tip Before creating and using interactive tables, you should become familiar with the limitations and use cases. Interactive tables work best with simple SELECT statements with selective WHERE clauses. This feature is generally available in select Amazon Web Services (AWS), Google Cloud Platform (GCP), and Microsoft Azure regions only. For details, see Region availability.

Syntax

supportedpartialnot supportednot scored

CREATE [ OR REPLACE ] INTERACTIVE TABLE [ IF NOT EXISTS ] <table_name>
  (
    <col_name> <col_type>
      [ [ WITH ] MASKING POLICY <policy_name> [ USING ( <col_name> , <cond_col1> , ... ) ] ]
      [ , <col_name> <col_type> [ ... ] ]
  )
  CLUSTER BY ( <expr> [ , <expr> , ... ] )
  [ TARGET_LAG = '<num> { seconds | minutes | hours | days }' ]
  [ WAREHOUSE = <warehouse_name> ]
  [ INITIALIZATION_WAREHOUSE = <warehouse_name> ]
  [ COMMENT = '<string_literal>' ]
  [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
  [ [ WITH ] ROW ACCESS POLICY <policy_name> ON ( <col_name> [ , <col_name> ... ] ) ]
  [ [ WITH ] AGGREGATION POLICY <policy_name> [ ENTITY KEY ( <col_name> [ , <col_name> ... ] ) ] ]
  [ [ WITH ] JOIN POLICY <policy_name> [ ALLOWED JOIN KEYS ( <col_name> [ , ... ] ) ] ]
  [ [ WITH ] STORAGE LIFECYCLE POLICY <policy_name> ON ( <col_name> [ , <col_name> ... ] ) ]
  AS <query>

Parameters

NameRequiredDescription
table_namerequiredSpecifies the identifier (i.e. name) for the interactive table; must be unique for the schema in which the table is created. In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (e.g. "My object"). Identifiers enclosed in double quotes are also case-sensitive. For more details, see Identifier requirements.
CLUSTER BY ( expr [ , expr , ... ] )requiredSpecifies one or more columns or column expressions in the table as the clustering key. Choose clustering columns that are used in the WHERE clauses of your most time-critical queries, as this significantly affects query performance. The clustering key can use up to 1 KB total across all columns in the CLUSTER BY clause. For more details about choosing effective clustering keys, see Clustering Keys & Clustered Tables.
AS queryrequiredSpecifies the SELECT statement that populates the interactive table. This query must be specified last in the CREATE INTERACTIVE TABLE statement, regardless of other parameters included. The query follows CREATE TABLE AS SELECT (CTAS) patterns and defines the data and schema for the interactive table.
col_namerequiredSpecifies the column identifier (i.e. name). Column identifiers must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes. For more details, see Identifier requirements.
col_typerequiredSpecifies the data type for the column. For details about the data types that can be specified for table columns, see SQL data types reference.
MASKING POLICY policy_nameoptionalSpecifies the masking policy to set on a column.
USING ( col_name , cond_col_1 ... )optionalSpecifies the arguments to pass into the conditional masking policy SQL expression. The first column in the list specifies the column for the policy conditions to mask or tokenize the data and must match the column to which the masking policy is set. The additional columns specify the columns to evaluate to determine whether to mask or tokenize the data in each row of the query result when a query is made on the first column. If the USING clause is omitted, Snowflake treats the conditional masking policy as a normal masking policy.
OR REPLACEoptionalSpecifies to replace the interactive table if it already exists in the schema. This is equivalent to using DROP TABLE on the existing table and then creating a new table with the same name.
IF NOT EXISTSoptionalSpecifies to create the interactive table only if it does not already exist in the schema. If a table with the same name already exists, the statement succeeds without creating a new table. Note The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive and cannot both be used in the same statement.
TARGET_LAG = 'num { seconds | minutes | hours | days }'optionalSpecifies the maximum lag time for automatic refresh of the interactive table. When specified, the interactive table becomes a dynamic interactive table that automatically refreshes to stay within the specified lag time of the source data. The minimum value is 60 seconds (1 minute). If no unit is specified, the number represents seconds. If TARGET_LAG is not specified, the table is created as a static interactive table. When TARGET_LAG is specified, the WAREHOUSE parameter is also required.
WAREHOUSE = warehouse_nameoptionalRequired when TARGET_LAG is specified. Specifies the standard warehouse used for refresh operations when TARGET_LAG is set. This must be a standard warehouse, not an interactive warehouse.
INITIALIZATION_WAREHOUSE = warehouse_nameoptionalSpecifies the standard warehouse used for initial refreshes when TARGET_LAG is set. Initial refreshes often process more data than later refreshes, so you can use a larger warehouse here than for WAREHOUSE. If not specified, the table uses the WAREHOUSE warehouse for all refreshes.
COMMENT = 'string_literal'optionalSpecifies a comment for the interactive table.
TAG ( tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ] )optionalSpecifies the tag name and the tag string value. The tag value is always a string, and the maximum number of characters for the tag value is 256. For information about specifying tags in a statement, see Tag quotas.
ROW ACCESS POLICY policy_name ON ( col_name [ , col_name ... ] )optionalSpecifies the row access policy to set on a table. This parameter is not supported by the CREATE OR ALTER variant syntax.
AGGREGATION POLICY policy_name [ ENTITY KEY ( col_name [ , col_name ... ] ) ]optionalSpecifies an aggregation policy to set on a table. You can apply one or more aggregation policies on a table. Use the optional ENTITY KEY parameter to define which columns uniquely identify an entity within the table. For more information, see Implementing entity-level privacy with aggregation policies. You can specify one or more entity keys for an aggregation policy.
JOIN POLICY policy_name [ ALLOWED JOIN KEYS ( col_name [ , ... ] ) ]optionalSpecifies the join policy to set on a table. Use the optional ALLOWED JOIN KEYS parameter to define which columns are allowed to be used as joining columns when this policy is in effect. For more information, see Join policies. This parameter is not supported by the CREATE OR ALTER variant syntax.
STORAGE LIFECYCLE POLICY policy_name ON ( col_name [ , col_name ... ] )optionalSpecifies a storage lifecycle policy to attach to the table. The columns specified in the ON clause must match the argument count and data types defined in the policy function signature. Snowflake uses these columns to evaluate the policy expression and determine which rows to archive or expire. Important If you attach an archival storage policy to a table, the table is permanently assigned to the specified archive tier for its lifetime. You can’t change the archive tier by applying a new policy. For example, you can’t specify a policy created with a COOL archive tier in ALTER TABLE…DROP STORAGE LIFECYCLE POLICY and then subsequently alter the table to add a policy created with a COLD archive tier. To alter the archive tier for a table, contact Snowflake Support to request deletion of the currently archived data. For additional considerations, see Archival storage policies. For more information about creating and managing storage lifecycle policies, see Create and manage storage lifecycle policies. This parameter is not supported by the CREATE OR ALTER variant syntax.

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE INTERACTIVE TABLE | Schema | Required to create an interactive table in the schema. SELECT | Table, external table, view | Required on queried tables and/or views in the AS SELECT clause. APPLY | Masking policy, row access policy, tag, storage lifecycle policy | Required only when applying a masking policy, row access policy, object tags, storage lifecycle policy, or any combination of these governance features when creating tables. USAGE | Database, Schema | Required on the database and schema containing the interactive table. Any other privilege on the database and schema also satisfies this requirement. USAGE | Warehouse | Required on the warehouses specified in the WAREHOUSE and INITIALIZATION_WAREHOUSE parameters (when TARGET_LAG is used). For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

Variant syntax: Static interactive table

Creates a static interactive table that is populated once from the source query: Static interactive tables don’t automatically refresh. They require manual updates to reflect changes in source data. To do so, run a CREATE OR REPLACE command or an INSERT OVERWRITE command on the interactive table.

Variant syntax: Dynamic interactive table

Creates a dynamic interactive table that automatically refreshes based on the specified lag time: Dynamic interactive tables automatically refresh to stay within the specified TARGET_LAG of the source data, using the specified standard warehouse for refresh operations.

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.

See also

Referenced by