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

This changes makes the macro easier to read and workable on SQL Server #3004

Merged

Conversation

mikaelene
Copy link
Contributor

resolves #3003

Description

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

@cla-bot cla-bot bot added the cla:yes label Jan 11, 2021
mikaelene added a commit to dbt-msft/dbt-sqlserver that referenced this pull request Jan 11, 2021
Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes a lot of sense to me, @mikaelene. Thanks for this.

I know it's not directly in the scope of the problem you're trying to solve, but I see that the same duplicated logic exists for the Postgres implementation here:

https://github.com/fishtown-analytics/dbt/blob/a4280d7457c32dce072d3224190a4779abc77d77/plugins/postgres/dbt/include/postgres/macros/materializations/snapshot_merge.sql#L5-L17

I think it would be simpler as just:

    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 in ('update'::text, 'delete'::text)
      and {{ target }}.dbt_valid_to is null;

Is that a change you'd be willing to make here as well, for greater consistency across adapters?

@mikaelene
Copy link
Contributor Author

Makes a lot of sense to me, @mikaelene. Thanks for this.

I know it's not directly in the scope of the problem you're trying to solve, but I see that the same duplicated logic exists for the Postgres implementation here:

Is that a change you'd be willing to make here as well, for greater consistency across adapters?

Changed in Postgres as well

@jtcohen6
Copy link
Contributor

jtcohen6 commented Jan 11, 2021

@cla-bot check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Snapshot_merge: 'WHEN MATCHED' cannot appear more than once in a 'UPDATE' clause of a MERGE statement
2 participants