Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-247] Support multiple unique_key for delete+insert incremental models (Postgres/Redshift/Snowflake/etc) #4738

Closed
jtcohen6 opened this issue Feb 17, 2022 · 3 comments
Labels
enhancement New feature or request incremental Incremental modeling with dbt Team:Adapters Issues designated for the adapter area of the code
Milestone

Comments

@jtcohen6
Copy link
Contributor

I'd previously thought this would be harder than it is: #4618 (comment)

When unique_key is a list, all we need to do is adjust the delete statement:

{% if unique_key is not none %}
delete from {{ target }}
where ({{ unique_key }}) in (
select ({{ unique_key }})
from {{ source }}
);
{% endif %}

To use using, which should enable multiple unique_key match conditions. Something like:

delete from analytics.my_model a
using my_model__dbt_tmp b
where a.unique_column_1 = b.unique_column_1
  and a.unique_column_2 = b.unique_column_2
  ...

And a test for it, of course :)

@jtcohen6 jtcohen6 added this to the v1.1 milestone Feb 17, 2022
@github-actions github-actions bot changed the title Support multiple unique_key for delete+insert incremental models (Postgres/Redshift/Snowflake/etc) [CT-247] Support multiple unique_key for delete+insert incremental models (Postgres/Redshift/Snowflake/etc) Feb 17, 2022
@jtcohen6 jtcohen6 added enhancement New feature or request incremental Incremental modeling with dbt Team:Adapters Issues designated for the adapter area of the code labels Feb 17, 2022
@leahwicz
Copy link
Contributor

@jtcohen6 is this for every adapter? Basically is that what "etc." meant?

@jtcohen6
Copy link
Contributor Author

jtcohen6 commented Mar 2, 2022

@leahwicz This change is relevant to any adapter that uses default__get_delete_insert_merge_sql. Postgres, Redshift, and Snowflake (specifically the delete+insert incremental strategy) are the only ones we need to be conscious of ourselves.

@jtcohen6
Copy link
Contributor Author

resolved by #4858

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request incremental Incremental modeling with dbt Team:Adapters Issues designated for the adapter area of the code
Projects
None yet
Development

No branches or pull requests

2 participants