CHANGES

constructsupportedQueries & DML

docs.snowflake.com ↗

The CHANGES clause enables querying the change tracking metadata for a table or view within a specified interval of time without having to create a stream with an explicit transactional offset. Multiple queries can retrieve the change tracking metadata between different transactional start and endpoints. Note Change tracking must be enabled on the source table or the source view and its underlying tables. For details, see the usage notes (in this topic). In a query, the CHANGES clause is specified in the FROM clause. The optional END keyword specifies the end of the change interval. The results are inclusive of the end marker.

Syntax

supportedpartialnot supportednot scored

SELECT ...
FROM ...
   CHANGES ( INFORMATION => { DEFAULT | APPEND_ONLY } )
   AT ( { TIMESTAMP => <timestamp> | OFFSET => <time_difference> | STATEMENT => <id> | STREAM => '<name>' } ) | BEFORE ( STATEMENT => <id> )
   [ END( { TIMESTAMP => <timestamp> | OFFSET => <time_difference> | STATEMENT => <id> } ) ]
[ ... ]

Parameters

NameRequiredDescription
INFORMATION => { DEFAULT | APPEND_ONLY }Specifies the type of change tracking data to return based on the metadata recorded in each:
  • DEFAULT — Returns all DML changes to the source object, including inserts, updates, and deletes (including table truncates). This type of change tracking compares inserted and deleted rows in the change set to provide the row level delta. As a net effect, for example, a row that is inserted and then deleted between two transactional points of time in a table is removed in the delta (i.e. is not returned in the query results).
  • APPEND_ONLY — Returns appended rows only; therefore no join is performed. As a result, querying append-only changes can be much more performant than querying standard (default) changes for extract, load, transform (ELT) and similar scenarios that depend exclusively on row inserts.
TIMESTAMP => timestampSpecifies the starting point of the change tracking interval. Changes from this timestamp to the current time, or to the END timestamp if specified, are returned. Note that the value must be explicitly cast to a TIMESTAMP.
OFFSET => time_differenceSpecifies the difference in seconds from the current time that sets the starting point of the change tracking interval, in the form -N where N can be an integer or arithmetic expression (e.g. -120 is 120 seconds, -30*60 is 1800 seconds or 30 minutes).
STATEMENT => idSpecifies the query ID of a statement to use as the starting point of the change tracking interval. This parameter supports any statement of one of the following types: DML (e.g. INSERT, UPDATE, DELETE) TCL (BEGIN, COMMIT transaction) SELECT
STREAM => 'name'Specifies the identifier (i.e. name) for an existing stream on the queried table or view. The current offset in the stream is used as the AT point in time for returning change data for the source object.

Usage notes

Parameters

INFORMATION => { DEFAULT | APPEND_ONLY }: Specifies the type of change tracking data to return based on the metadata recorded in each: DEFAULT: Returns all DML changes to the source object, including inserts, updates, and deletes (including table truncates). This type of change tracking compares inserted and deleted rows in the change set to provide the row level delta. As a net effect, for example, a row that is inserted and then deleted between two transactional points of time in a table is removed in the delta (i.e. is not returned in the query results). APPEND_ONLY: Returns appended rows only; therefore no join is performed. As a result, querying append-only changes can be much more performant than querying standard (default) changes for extract, load, transform (ELT) and similar scenarios that depend exclusively on row inserts. TIMESTAMP => timestamp: Specifies the starting point of the change tracking interval. Changes from this timestamp to the current time, or to the END timestamp if specified, are returned. Note that the value must be explicitly cast to a TIMESTAMP. OFFSET => time_difference: Specifies the difference in seconds from the current time that sets the starting point of the change tracking interval, in the form -N where N can be an integer or arithmetic expression (e.g. -120 is 120 seconds, -30*60 is 1800 seconds or 30 minutes). STATEMENT => id: Specifies the query ID of a statement to use as the starting point of the change tracking interval. This parameter supports any statement of one of the following types: DML (e.g. INSERT, UPDATE, DELETE) TCL (BEGIN, COMMIT transaction) SELECT STREAM => 'name': Specifies the identifier (i.e. name) for an existing stream on the queried table or view. The current offset in the stream is used as the AT point in time for returning change data for the source object.

Referenced by