Skip to content

Commit

Permalink
delete+insert requires incremental_predicates if there's no unique_key
Browse files Browse the repository at this point in the history
This allows us to perform fine-grained optimizations that does
not rely on the unique key. This optimization is important for
data warehouses like Redshift, where there is no concept of
primary/unique keys and indexes.
  • Loading branch information
dlord committed Oct 3, 2024
1 parent 10e6d59 commit d9e67c6
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@
{%- endif -%};

{% endif %}
{% else %}
{% if not incremental_predicates %}
{{ exceptions.raise_compiler_error("incremental_predicates is required when there is no unique_key") }}
{% endif %}

delete from {{ target }}
where (
{% for predicate in incremental_predicates %}
{{ predicate|replace('DBT_INTERNAL_DEST', target)|replace('DBT_INTERNAL_SOURCE', source) }}
{{ "and " if not loop.last}}
{% endfor %}
);
{% endif %}

insert into {{ target }} ({{ dest_cols_csv }})
Expand Down

0 comments on commit d9e67c6

Please sign in to comment.