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

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

Closed
mikaelene opened this issue Jan 11, 2021 · 2 comments · Fixed by #3004
Labels
enhancement New feature or request

Comments

@mikaelene
Copy link
Contributor

Describe the feature

The SQL generated for updating records in merge statements generated by snapshots does not work on SQL Server.

Describe alternatives you've considered

I want it to work on SQL Server as well as all other databases.

Additional context

This applies to SQL Server, but it could be better written anyway to not confuse developers.

Who will this benefit?

SQL Server dbt users

Are you interested in contributing this feature?

I can make a PR solving this

@mikaelene mikaelene added enhancement New feature or request triage labels Jan 11, 2021
@mikaelene
Copy link
Contributor Author

https://github.com/fishtown-analytics/dbt/blob/a4280d7457c32dce072d3224190a4779abc77d77/core/dbt/include/global_project/macros/materializations/snapshot/snapshot_merge.sql#L14-L24

could be rewritten as

    when matched
     and DBT_INTERNAL_DEST.dbt_valid_to is null
     and DBT_INTERNAL_SOURCE.dbt_change_type in ('update', 'delete')
        then update
        set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to

mikaelene added a commit to mikaelene/dbt that referenced this issue Jan 11, 2021
…or SQL Server without a custom adapter macro. Solved dbt-labs#3003
mikaelene added a commit to mikaelene/dbt that referenced this issue Jan 11, 2021
…or SQL Server without a custom adapter macro. Solved dbt-labs#3003
@jtcohen6 jtcohen6 removed the triage label Jan 11, 2021
@jtcohen6
Copy link
Contributor

Agree that the more concise version is preferable, anyway!

mikaelene added a commit to mikaelene/dbt that referenced this issue Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants