Skip to content

Commit

Permalink
Update snapshot_merge.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Aug 28, 2024
1 parent 5575fa8 commit 13e5655
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
{% macro postgres__snapshot_merge_sql(target, source, insert_cols) -%}
{%- set insert_cols_csv = insert_cols | join(', ') -%}

{%- set dbt_scd_id = config.get("dbt_scd_id_column_name") or "dbt_scd_id" -%}
{%- set dbt_valid_to = config.get("dbt_valid_to_column_name") or "dbt_valid_to" -%}

update {{ target }}
set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to
set {{ dbt_valid_to }} = DBT_INTERNAL_SOURCE.{{ dbt_valid_to }}
from {{ source }} as DBT_INTERNAL_SOURCE
where DBT_INTERNAL_SOURCE.dbt_scd_id::text = {{ target }}.dbt_scd_id::text
where DBT_INTERNAL_SOURCE.{{ dbt_scd_id }}::text = {{ target }}.{{ dbt_scd_id }}::text
and DBT_INTERNAL_SOURCE.dbt_change_type::text in ('update'::text, 'delete'::text)
and {{ target }}.dbt_valid_to is null;
and {{ target }}.{{ dbt_valid_to }} is null;

insert into {{ target }} ({{ insert_cols_csv }})
select {% for column in insert_cols -%}
Expand Down

0 comments on commit 13e5655

Please sign in to comment.