Use more than one key as incremental unique_key

Can I use multiple keys as unique_key in config?
e.g. Something like this: unique_key = ['date_sk', 'campaign_id', 'message_type', 'variation_name']

Hey @nicor88! Great question. unique_key accepts any valid SQL. So, you could do:

unique_key = 'field_1 || field_2 || field_3'

…or something similar. Generally, what we recommend is for all models to include a unique key in the contents of the model itself. This helps with uniqueness testing so that you can avoid fanout errors in your SQL. If there is no natural key in the underlying data and you need to create a surrogate key, I’d recommend using the surrogate key macro in dbt-utils to create one. Then you can easily pass that field into the unique_key config.

As of dbt Core 1.1, a list of column values is supported, exactly in the way you described :tada:

See the docs for more info: Configuring incremental models | dbt Docs

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.