diff --git a/CHANGELOG.md b/CHANGELOG.md index 55ccd4a388c..fc0076fa913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ ## dbt 0.19.0 (Release TBD) ### Under the hood +- Rewrite macro for snapshot_merge_sql to make compatible with other SQL dialects ([#3003](https://github.com/fishtown-analytics/dbt/pull/3003) - Rewrite logic in `snapshot_check_strategy()` to make compatible with other SQL dialects ([#3000](https://github.com/fishtown-analytics/dbt/pull/3000), [#3001](https://github.com/fishtown-analytics/dbt/pull/3001)) Contributors: +- [@mikaelene](https://github.com/mikaelene) ([#3003](https://github.com/fishtown-analytics/dbt/pull/3003)) - [@dbeatty10](https://github.com/dbeatty10) ([dbt-adapter-tests#10](https://github.com/fishtown-analytics/dbt-adapter-tests/pull/10)) - [@swanderz](https://github.com/swanderz) ([#3000](https://github.com/fishtown-analytics/dbt/pull/3000)) diff --git a/core/dbt/include/global_project/macros/materializations/snapshot/snapshot_merge.sql b/core/dbt/include/global_project/macros/materializations/snapshot/snapshot_merge.sql index 74bfa2b32d3..9d97af510b5 100644 --- a/core/dbt/include/global_project/macros/materializations/snapshot/snapshot_merge.sql +++ b/core/dbt/include/global_project/macros/materializations/snapshot/snapshot_merge.sql @@ -13,13 +13,7 @@ when matched and DBT_INTERNAL_DEST.dbt_valid_to is null - and DBT_INTERNAL_SOURCE.dbt_change_type = 'update' - then update - set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to - - when matched - and DBT_INTERNAL_DEST.dbt_valid_to is null - and DBT_INTERNAL_SOURCE.dbt_change_type = 'delete' + and DBT_INTERNAL_SOURCE.dbt_change_type in ('update', 'delete') then update set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to diff --git a/plugins/postgres/dbt/include/postgres/macros/materializations/snapshot_merge.sql b/plugins/postgres/dbt/include/postgres/macros/materializations/snapshot_merge.sql index ba016c83a6a..807c70b6c02 100644 --- a/plugins/postgres/dbt/include/postgres/macros/materializations/snapshot_merge.sql +++ b/plugins/postgres/dbt/include/postgres/macros/materializations/snapshot_merge.sql @@ -6,14 +6,7 @@ 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 - and DBT_INTERNAL_SOURCE.dbt_change_type::text = 'update'::text - and {{ target }}.dbt_valid_to is null; - - update {{ target }} - 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 - and DBT_INTERNAL_SOURCE.dbt_change_type::text = 'delete'::text + and DBT_INTERNAL_SOURCE.dbt_change_type::text in ('update'::text, 'delete'::text) and {{ target }}.dbt_valid_to is null; insert into {{ target }} ({{ insert_cols_csv }})