Search code examples
jinja2dbt

Operator to concatenate two dbt Jinja sets?


In a given model, I am using two macros to create sets for a later loop.

Adapting the example from the docs, it looks something like this:

{% set pay_1 = ["bank_transfer"] %}
{% set pay_2 = ["credit_card", "gift_card"] %}
{% set payment_methods = pay_1 + pay_2 %}

{% for payment_method in payment_methods %}
...
{% endfor %}

What is the syntax for the pseudo code pay_1 + pay_2 to combine these two set variables as above?


Solution

  • Your code, as written works. The value of payment_methods at the end of your code is

    ['bank_transfer', 'credit_card', 'gift_card']
    

    It's worth pointing out that these are lists, not sets. If items are duplicated across your list, they will be duplicated in the result. As far as I know, there is not support for sets in dbt-jinja.