I'm working on making an dbt model incremental, but when calling {% if is_incremental() %} it fails to find the original column name: Unrecognized name: date_consultation_scheduled_tz at [4:17] However that column is indeed there because I can see it in the database and there are other models using that field, however anytime I call for incremental it breaks.
My original code looks like this:
{% set is_holiday_column = "check_holiday_region_" ~ region.lower() %}
{{
config(
materialized='incremental',
tags=[ "fact_final_table"]
)
}}
select
client_id
, time_to_call
, consultation_scheduled_date
, abs({{count_not_work_days('weekend', 'date_screened', 'consultation_scheduled_date')}}) as calc_time_to_call_weekday
, abs({{count_not_work_days('holidays', 'date_screened', 'consultation_scheduled_date')}}) as calc_time_to_call_holidays
from(
select
patient_sword_id
, date(date_screened_at) as date_screened
, date(date_consultation_scheduled_tz) as consultation_scheduled_date
, abs(date_diff(date(date_screened), date(date_consultation_scheduled_tz), day)) as time_to_call
from {{ref ('dimension_clients_table')}}
)
{% if is_incremental() %}
WHERE DATE(consultation_scheduled_date) >= DATE("{{ macro_incremental_max_date('consultation_scheduled_date') }}")
{% endif %}
I thought I had the where clause in the wrong place so I moved it inside the subquery
select
client_id
, time_to_call
, consultation_scheduled_date
, abs({{count_not_work_days('weekend', 'date_screened', 'consultation_scheduled_date')}}) as calc_time_to_call_weekday
, abs({{count_not_work_days('holidays', 'date_screened', 'consultation_scheduled_date')}}) as calc_time_to_call_holidays
from(
select
client_id
, date(date_screened_at) as date_screened
, date(date_consultation_scheduled_tz) as consultation_scheduled_date
, abs(date_diff(date(date_screened), date(date_consultation_scheduled_tz), day)) as time_to_call
from {{ref ('dimension_clients_table')}}
{% if is_incremental() %}
WHERE DATE(consultation_scheduled_date) >= DATE("{{ macro_incremental_max_date('consultation_scheduled_date') }}")
{% endif %}
)```
That still gave the same error.
From there I thought if I removed the subquery and focus on that snippet of code itself I would figure out what I had missed in there.
Still gives ```Unrecognized name: date_consultation_scheduled_tz at [4:17]```