I have a variable defined in my dbt_project.yml
file as a set. I want to extend this set by adding a single string element to it or in future potentially another set.
Here a template of what my dbt_project.yml
currently looks like:
vars:
var1_tuple: [item1, item2, item3] # existing set
var2: '{{ (var('var1') + ['install']) | join(", ") }}'
Then in table.sql
WHERE column1 "{{ var('var2') }}"
But when I call this variable var2
from the SQL code, the code breaks as it doesn't correctly parse the var as a SQL set but rather as a string.
How can I correctly parse var2
?
Jinja treats tuples differently: in order to append something into a tuple, you first need to convert it into an array. On the other hand, you should also set the value you want to append into an array.
So, the following should work:
From here, if you run something like:
{% do log(var('my_other_var'), info=True) %}
you should be seeing:
['item1', 'item2', 'item3', 'item4']