Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
{%- set insert_cols_csv = get_quoted_csv(get_columns_in_relation(target) | map(attribute="name")) %}
{% endif %}

{%- set dbt_valid_to = config.get('dbt_valid_to_current', 'null') -%}

merge into {{ target }} as DBT_INTERNAL_DEST
using {{ source }} as DBT_INTERNAL_SOURCE
on DBT_INTERNAL_SOURCE.dbt_scd_id = DBT_INTERNAL_DEST.dbt_scd_id

when matched
and DBT_INTERNAL_DEST.dbt_valid_to is null
and
{% if dbt_valid_to == 'null' %}
DBT_INTERNAL_DEST.dbt_valid_to is null
{% else %}
DBT_INTERNAL_DEST.dbt_valid_to = {{ dbt_valid_to }}
{% endif %}
and DBT_INTERNAL_SOURCE.dbt_change_type in ('update', 'delete')
then update
set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to
Expand Down