With a unique key in the .yml file, the merge statement in an incremental model looks like this:
merge into `bigquery_table_tgt` as DBT_INTERNAL_DEST
using (
select * from `bigquery_table_tgt__dbt_tmp`
) as DBT_INTERNAL_SOURCE
on
DBT_INTERNAL_SOURCE.key = DBT_INTERNAL_DEST.key
when matched then update set
`key` = DBT_INTERNAL_SOURCE.`key` --etc
when not matched then insert
(columns etc)
values
(values etc)
A user asked how to achieve insert only in an incremental model and the proposed solution was to remove the unique key in the .yml file.
Without a unique key in the .yml file, the merge statement looks like this:
merge into bigquery_table_tgt
as DBT_INTERNAL_DEST
using (
select * from bigquery_table_tgt__dbt_tmp
) as DBT_INTERNAL_SOURCE
on FALSE
#no join on source/target ->> you will have to check source against target yourself to avoid duplicates
when not matched then insert
(columns etc)
values
(values etc)
The solution I really would like to see is this
With a unique key in the .yml file:
#new feature in dbt:
merge_option: insert_only
merge into `bigquery_table_tgt` as DBT_INTERNAL_DEST
using (
select * from `bigquery_table_tgt__dbt_tmp`
) as DBT_INTERNAL_SOURCE
on
DBT_INTERNAL_SOURCE.key = DBT_INTERNAL_DEST.key
# remove the following statement when merge_option = insert_only
# when matched then update set `key` = DBT_INTERNAL_SOURCE.`key` --etc
#but of course keep this:
when not matched then insert
(columns etc)
values
(values etc)
Will this kind of feature ever show up in dbt?