diff --git a/.changes/unreleased/Features-20240927-133708.yaml b/.changes/unreleased/Features-20240927-133708.yaml new file mode 100644 index 00000000..b2dba333 --- /dev/null +++ b/.changes/unreleased/Features-20240927-133708.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Enable setting current value of dbt_valid_to +time: 2024-09-27T13:37:08.808843-04:00 +custom: + Author: gshank + Issue: "151" diff --git a/dbt/include/postgres/macros/materializations/snapshot_merge.sql b/dbt/include/postgres/macros/materializations/snapshot_merge.sql index 894ea4b4..0b4deb1b 100644 --- a/dbt/include/postgres/macros/materializations/snapshot_merge.sql +++ b/dbt/include/postgres/macros/materializations/snapshot_merge.sql @@ -9,7 +9,12 @@ from {{ source }} as DBT_INTERNAL_SOURCE 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) - and {{ target }}.{{ columns.dbt_valid_to }} is null; + {% if 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 %} + insert into {{ target }} ({{ insert_cols_csv }}) select {% for column in insert_cols -%}