CREATE EVENT TABLE

statementpartialTables, views, streams, sequences

docs.snowflake.com ↗

Object: EVENT TABLE

Creates an event table that captures events, including logged messages from functions and procedures.

Syntax

supportedpartialnot supportednot scored

CREATE [ OR REPLACE ] EVENT TABLE [ IF NOT EXISTS ] <name>
  [ CLUSTER BY ( <expr> [ , <expr> , ... ] ) ]
  [ DATA_RETENTION_TIME_IN_DAYS = <integer> ]
  [ MAX_DATA_EXTENSION_TIME_IN_DAYS = <integer> ]
  [ CHANGE_TRACKING = { TRUE | FALSE } ]
  [ DEFAULT_DDL_COLLATION = '<collation_specification>' ]
  [ COPY GRANTS ]
  [ COPY = ( GRANTS ) ]
  [ [ WITH ] COMMENT = '<string_literal>' ]
  [ [ WITH ] ROW ACCESS POLICY <policy_name> ON ( <col_name> [ , <col_name> ... ] ) ]
  [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
  [ WITH CONTACT ( <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ) ]

Creates a new event table with the same predefined column definitions and containing all the existing data from the source table without actually copying the data. You can also use this variant to clone an event table at a specific time/point in the past (using Time Travel)

CREATE [ OR REPLACE ] EVENT TABLE [ IF NOT EXISTS ] <name>
  CLONE <source_table>
    [ { AT | BEFORE } ( { TIMESTAMP => <timestamp> | OFFSET => <time_difference> | STATEMENT => <id> } ) ]
    [ COPY GRANTS ]
    [ ... ]

Parameters

NameRequiredDescription
namerequiredSpecifies the identifier (the name) for the event table; must be unique for the schema in which the event 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.
source_tablerequiredRequired for CLONE. Specifies the event table to use as the source for the clone.
CLUSTER BY ( expr [ , expr , ... ] )optionalSpecifies one or more columns or column expressions in the table as the clustering key. For more details, see Clustering Keys & Clustered Tables. Default: No value (no clustering key is defined for the table) Important Clustering keys are not intended or recommended for all tables; they typically benefit very large (i.e. multi-terabyte) tables. Before you specify a clustering key for a table, please read Understanding Snowflake Table Structures.
DATA_RETENTION_TIME_IN_DAYS = integeroptionalSpecifies the retention period for the table so that Time Travel actions (SELECT, CLONE, UNDROP) can be performed on historical data in the table. For more details, see Understanding & using Time Travel. For a detailed description of this object-level parameter, as well as more information about object parameters, see Parameters. Values: Standard Edition: 0 or 1 Enterprise Edition: 0 to 90 for permanent tables Default: Standard Edition: 1 Enterprise Edition (or higher): 1 (unless a different default value was specified at the schema, database, or account level) Note A value of 0 effectively disables Time Travel for the table.
MAX_DATA_EXTENSION_TIME_IN_DAYS = integeroptionalObject parameter that specifies the maximum number of days for which Snowflake can extend the data retention period for the table to prevent streams on the table from becoming stale. For a detailed description of this parameter, see MAX_DATA_EXTENSION_TIME_IN_DAYS.
CHANGE_TRACKING = { TRUE | FALSE }optionalSpecifies whether to enable change tracking on the table. TRUE enables change tracking on the table. This setting adds a pair of hidden columns to the source table and begins storing change tracking metadata in the columns. These columns consume a small amount of storage. The change tracking metadata can be queried using the CHANGES clause for SELECT statements, or by creating and querying one or more streams on the table. FALSE does not enable change tracking on the table. Default: FALSE
DEFAULT_DDL_COLLATION = 'collation_specification'optionalSpecifies a default collation specification for the columns in the table. For more details about the parameter, see DEFAULT_DDL_COLLATION.
COPY GRANTSoptionalSpecifies to retain the access privileges from the original table when a new table is created using any of the following CREATE TABLE variants: CREATE OR REPLACE EVENT TABLE CREATE EVENT TABLE … CLONE The parameter copies all privileges, except OWNERSHIP, from the existing table to the new table. The new table does not inherit any future grants defined for the object type in the schema. By default, the role that executes the CREATE EVENT TABLE statement owns the new table. If the parameter is not included in the CREATE EVENT TABLE statement, then the new table does not inherit any explicit access privileges granted on the original table, but does inherit any future grants defined for the object type in the schema. Note: The SHOW GRANTS output for the replacement table lists the grantee for the copied privileges as the role that executed the CREATE EVENT TABLE statement, with the current timestamp when the statement was executed. The operation to copy grants occurs atomically in the CREATE EVENT TABLE command (in other words, within the same transaction). You can also copy grants with the COPY = ( GRANTS ) parameter. For event tables, COPY = ( ... ) accepts only GRANTS. In the CLONE form, specify the parameter before the CLONE keyword.
ROW ACCESS POLICY policy_name ON ( col_name [ , col_name ... ] )optionalSpecifies the row access policy to set on a table.
COMMENT = 'string_literal'optionalSpecifies a comment for the table. Default: No value
WITH DATA METRIC FUNCTION ( dmf_name ON ( col_name [ , col_name ... ] ) [ , dmf_binding ... ] )optionalAssociates one or more data metric functions (DMFs) with the event table at creation time. The DMF begins running on the schedule configured for the table as soon as it is created. You can attach multiple DMF bindings by separating them with commas. Each binding accepts the same properties as ALTER TABLE … ADD DATA METRIC FUNCTION, including EXECUTE AS ROLE, ANOMALY_DETECTION, SENSITIVITY, DATA_QUALITY_NOTIFICATION, and EXPECTATION. For a description of each property, see Data metric function actions. Snowflake also accepts this clause without the parentheses around the binding list, but that form is deprecated and a future behavior change release removes it. For usage guidance and examples, see Attach DMFs at creation time. Default: No value (no DMF is associated with the event 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.
WITH CONTACT ( purpose = contact [ , purpose = contact ...] )optionalAssociate the new object with one or more contacts. Specify the WITH CONTACT clause after all other clauses except the AS clause (if that clause is supported by this command).

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE EVENT TABLE | Schema in which you plan to create the event table. | Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. 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.

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.

See also

Referenced by