Below is my code in dbt_project.yml file
vars:
# Variable
project1:
vendor:
ABC
DEF
ABC:
model:
name: model123
case_types:
name: CASE1
name: CASE2
name: CASE3
name: CASE4
the way i am trying to access this in model is below. When the below code is run the values in src are ('model' & 'case_types') respectively. How do i access values of these( 'model123, CASE1, CASE2....)
{% set vars1 = var('ABC') %}
{% for src in vars1 %}
{{log(src, True)}}
{% endfor %}
You can reference nested variables using square bracket notation following the var('') command that references the top-most variable.
For example, if I have a dbt_project.yml file with the following:
vars:
model_1:
start_date: 2020-01-31
end_date: 2020-12-31
model_2:
start_date: 2021-01-31
end_date: 2021-12-31
I could reference the sub variables by:
SELECT *
FROM table
WHERE
model_number = 1
AND as_of_date BETWEEN '{{ var("model_1")["start_date"] }}'::DATE AND '{{ var("model_1")["end_date"] }}'::DATE
I have not, however, been able to reference a variable within a {% %} block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With