diff --git a/synapse_data_warehouse/synapse/dynamic_tables/V2.24.0__projectsettings_latest.sql b/synapse_data_warehouse/synapse/dynamic_tables/V2.24.0__projectsettings_latest.sql new file mode 100644 index 0000000..c85ab34 --- /dev/null +++ b/synapse_data_warehouse/synapse/dynamic_tables/V2.24.0__projectsettings_latest.sql @@ -0,0 +1,24 @@ +use schema {{database_name}}.synapse; --noqa: JJ01,PRS,TMP,CP01 + +CREATE DYNAMIC TABLE IF NOT EXISTS PROJECTSETTING_LATEST + TARGET_LAG = '1 day' + WAREHOUSE = compute_xsmall + AS + WITH latest_unique_rows AS ( + SELECT + * + FROM + {{database_name}}.synapse_raw.projectsettingsnapshots --noqa: TMP + WHERE + SNAPSHOT_TIMESTAMP >= CURRENT_TIMESTAMP - INTERVAL '14 DAYS' + QUALIFY ROW_NUMBER() OVER ( + PARTITION BY id + ORDER BY change_timestamp DESC, snapshot_timestamp DESC + ) = 1 + ) + SELECT + * + FROM + latest_unique_rows + ORDER BY + latest_unique_rows.id ASC;