When using incremental strategies with the incremental model, building the model fails on an incremental run with an error (column ... is ambiguous)
The reason is probably that in the generated MERGE INTO statment, the columns are not prefixed with DBT_INTERNAL_SOURCE in the statements following "when not matched then insert"
` merge into [TABLE] as DBT_INTERNAL_DEST
using [TABLE] as DBT_INTERNAL_SOURCE
on (
DBT_INTERNAL_SOURCE.id = DBT_INTERNAL_DEST.id
) when matched then update set
"id" = DBT_INTERNAL_SOURCE."id","col" = DBT_INTERNAL_SOURCE."col"
when not matched then insert
("id", "col")
values
("id", "col")`
Expected Behavior
Incremental models with merge strategy should work
select 1 AS id, 1 AS col
UNION
select 2 AS id, 2 AS col
UNION
select 3 AS id, 2 AS col
{% if is_incremental() %}
UNION select 4 as id, 4 as col
{% endif %}
the first time (non-incremental run) it works fine. On the second run, it will fail with error Column 'id' is ambiguous
Is there an existing issue for this?
Current Behavior
When using incremental strategies with the incremental model, building the model fails on an incremental run with an error (column ... is ambiguous)
The reason is probably that in the generated MERGE INTO statment, the columns are not prefixed with DBT_INTERNAL_SOURCE in the statements following "when not matched then insert"
` merge into [TABLE] as DBT_INTERNAL_DEST using [TABLE] as DBT_INTERNAL_SOURCE on ( DBT_INTERNAL_SOURCE.id = DBT_INTERNAL_DEST.id ) when matched then update set "id" = DBT_INTERNAL_SOURCE."id","col" = DBT_INTERNAL_SOURCE."col"
Expected Behavior
Incremental models with merge strategy should work
Steps To Reproduce
Run this example Model:
{{ config( materialized="incremental", incremental_strategy="merge", unique_key="id" ) }}
select 1 AS id, 1 AS col UNION select 2 AS id, 2 AS col UNION select 3 AS id, 2 AS col {% if is_incremental() %} UNION select 4 as id, 4 as col {% endif %}
the first time (non-incremental run) it works fine. On the second run, it will fail with error Column 'id' is ambiguous
Environment
Relevant log output