I am trying to use environment variables in an if statement in dbt jinja.
{{
config(
materialized='incremental',
pre_hook="
{% if env_var('dbt_evar_curr_annual') == 'Y' %}
Truncate {{this}}
{% endif %}
"
)
}}
SELECT
{% if env_var('dbt_evar_curr_annual') == 'Y' %}
1 As ID,
'annual' As NAME
{% else %}
2 As ID,
{{env_var('dbt_evar_curr_annual')}} As NAME
{% endif %}
FROM DUAL
I could see that my final table is getting loaded with a row of values 2,Y. That means I am correctly passing environment variables correctly as follows.
dbt run -m test_if3 --vars {dbt_evar_curr_annual:Y}
Can You please help me understand what is issue with my if statement.