The problem I’m having
I use a dbt model to transform data in a postgres db. When I run an incremental model more than once it runs into an error complaining about a missing column. The error occurs only when I define a unique key.
The context of why I’m trying to do this
I use an incremental model to append new data to a table. In my understanding the dbt model has to be executed every time new data is loaded to the db.
Some example code or error messages
This is my model:
{{ config(
materialized='incremental',
unique_key = ‘Date1, product’
alias=‘units’
) }}
select
mu.index,
mu."Date1”,
mu.product,
mu.units
from {{ source('sc’,’table_raw’) }} mu
{% if is_incremental() %}
where mu."Date1" > (select max("Date1") from {{ this }})
{% endif %}
order by product, mu."Date1"
This is the translated error :
ERROR: Column »date1« does not exist
LINE 8: select (Date1, product)
^
HINT: Perhaps the intention is to refer to column »units__dbt_tmp220418107752.Date1« or to the column »units.Date1«.