From 9defe6b7c6fa754c0d231cf9607fa4ffea7bdf7f Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Fri, 27 Sep 2024 13:27:49 -0400 Subject: [PATCH] Check both dbt_valid_to_current and null --- dbt/include/postgres/macros/materializations/snapshot_merge.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/include/postgres/macros/materializations/snapshot_merge.sql b/dbt/include/postgres/macros/materializations/snapshot_merge.sql index d59517dc..0b4deb1b 100644 --- a/dbt/include/postgres/macros/materializations/snapshot_merge.sql +++ b/dbt/include/postgres/macros/materializations/snapshot_merge.sql @@ -10,7 +10,7 @@ where DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }}::text = {{ target }}.{{ columns.dbt_scd_id }}::text and DBT_INTERNAL_SOURCE.dbt_change_type::text in ('update'::text, 'delete'::text) {% if config.get("dbt_valid_to_current") %} - and {{ target }}.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current') }}; + and ({{ target }}.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current') }} or {{ target }}.{{ columns.dbt_valid_to }} is null); {% else %} and {{ target }}.{{ columns.dbt_valid_to }} is null; {% endif %}