SOURCE_TARGET_LAG

functionsupportedGovernance (policies, tags, data quality)Enterprise+

docs.snowflake.com ↗

Data metric functions

Returns how far, in seconds, the latest timestamp in a target table trails the latest timestamp in a source table. Use this function to monitor whether a table that is loaded from another table, such as a replica or the output of a pipeline, is keeping up with its source. You associate the function with the target table and specify the source table as a reference table argument. Data Quality Monitoring requires Enterprise Edition. To inquire about upgrading, please contact Snowflake Support.

Syntax

To associate the function with a table

ALTER TABLE <target_table>
  ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.SOURCE_TARGET_LAG
    ON ( <target_column>, TABLE( <source_table>( <source_column> ) ) )

To call the function directly

SNOWFLAKE.CORE.SOURCE_TARGET_LAG( ( <target_query> ), ( <source_query> ) )

Parameters

NameRequiredDescription
target_columnrequiredSpecifies the timestamp column in the associated (target) table.
TABLE(source_table(source_column))requiredSpecifies the source table and its timestamp column: source_table: The fully qualified name of the source table (for example, my_db.my_schema.my_table). source_column: The timestamp column in the source table.
target_query, source_queryrequiredSpecifies two SQL queries, each enclosed in parentheses, when you call the function directly. Each query must project a single timestamp column. The first query reads the target, and the second query reads the source.

Returns

The function returns a NUMBER value: the latest source timestamp minus the latest target timestamp, in seconds. - A positive value means that the target trails the source by that number of seconds. - A negative value means that the target is ahead of the source. - A value of 0 means that the latest timestamps are equal. For DATE columns, the value is a whole number of days expressed in seconds. For example, a difference of two days returns 172800. NULL values are ignored. The function returns NULL if either the target or the source has no non-NULL timestamp.

Usage notes

Allowed data types

The target and source columns must have the same data type, which must be one of the following: - DATE - TIMESTAMP_LTZ - TIMESTAMP_NTZ - TIMESTAMP_TZ