Skip to content

fix: enable multikey snapshots#630

Closed
hoesler wants to merge 1 commit into
dbt-msft:masterfrom
hoesler:fix-multikey-snapshots
Closed

fix: enable multikey snapshots#630
hoesler wants to merge 1 commit into
dbt-msft:masterfrom
hoesler:fix-multikey-snapshots

Conversation

@hoesler
Copy link
Copy Markdown

@hoesler hoesler commented Jan 21, 2026

This PR fixes #615 by adding dynamic column filtering for multiple unique keys

@axellpadilla
Copy link
Copy Markdown
Collaborator

Thanks, closing because the current master version and (v1.9.1) of:

dbt/include/sqlserver/macros/materializations/snapshots/snapshot.sql

already contains the multi-key exclusion logic:

{% set remove_columns = ['dbt_change_type', 'DBT_CHANGE_TYPE', 'dbt_unique_key', 'DBT_UNIQUE_KEY'] %}

{% if unique_key | is_list %}
{% for key in strategy.unique_key %}
{{ remove_columns.append('dbt_unique_key_' + loop.index|string) }}
{{ remove_columns.append('DBT_UNIQUE_KEY_' + loop.index|string) }}
{% endfor %}
{% endif %}

{% set missing_columns = adapter.get_missing_columns(staging_table, target_relation)
| rejectattr('name', 'in', remove_columns)
| list %}

{% set source_columns = adapter.get_columns_in_relation(staging_table)
| rejectattr('name', 'in', remove_columns)
| list %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snapshots aren't correctly handling multiple unique_key values

2 participants