Skip to content

Commit

Permalink
Adding support of multiple values for unique key col (#116)
Browse files Browse the repository at this point in the history
Co-authored-by: nrodriguezmicrofocus <[email protected]>
Co-authored-by: nrodriguezmicrofocus <[email protected]>
  • Loading branch information
3 people authored Nov 23, 2023
1 parent 46f597a commit 8b03263
Showing 1 changed file with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

merge into {{ target_relation }} as DBT_INTERNAL_DEST
using {{ tmp_relation }} as DBT_INTERNAL_SOURCE



{#-- Test 1, find the provided merge columns #}
{% if merge_columns %}
on
{% for column in [merge_columns] %}
on
{% if merge_columns is string %}
DBT_INTERNAL_DEST.{{ adapter.quote(merge_columns) }} = DBT_INTERNAL_SOURCE.{{ adapter.quote(merge_columns) }}
{% else %}
{% for column in merge_columns -%}
DBT_INTERNAL_DEST.{{ adapter.quote(column) }} = DBT_INTERNAL_SOURCE.{{ adapter.quote(column) }}
{%- if not loop.last %} AND {% endif %}
{%- endfor %}
{% endif %}
{#-- Test 2, use all columns in the destination table #}
{% else %}
on
Expand Down Expand Up @@ -54,12 +59,29 @@
{%- set dest_cols_csv = get_quoted_csv(dest_columns | map(attribute="name")) -%}

{% if unique_key %}
{% if unique_key is string %}
delete from {{ target }}
where
({{ unique_key }}) in (
select ({{ unique_key }})
from {{ source }}
)


;
{% else %}
delete from {{ target }}
where (
{{ unique_key }}) in (
select ({{ unique_key }})
from {{ source }}
);
where
{% for column in unique_key -%}
({{ column }}) in (
select ({{ column }})
from {{ source }}
)
{%- if not loop.last %} AND {% endif %}
{%- endfor %}

;
{% endif%}

{% endif %}

Expand Down

0 comments on commit 8b03263

Please sign in to comment.