Handling Merge to update the existing records and inserting the New records

Hi Folks,
I am new to dbt. Recently we are doing migration from Hive to BQ. We are converting all our ETL process to dbt. I am facing issue regarding Merge. how can I apply MERGE when some of conditions looks like:

when matched and [col a] <> [col b]
then update [col a] = [col b]

when not matched
then insert
values (
col a,
col b)

I need to update rows only when matched and only when its not equals and also I need to insert the new records if not matched.

Thanks in advance

In dbt we don’t need to write a merge statement.
Have a look at incremental models, you can specify a unique key so that it will do what you are after


Note: @Meagan Palmer (Altis) originally posted this reply in Slack. It might not have transferred perfectly.