'Using jinja sql variables in dbt_utils

In my dbt project, if I declare a jinja sql variable how can I pass it to a dbt_utils function?

For example this doesn't work:

{% set exclude_columns = ["col1", "col2", "col3"] %}

SELECT {{ dbt_utils.star(from=ref('table'), except=exclude_columns) }}
FROM {{ ref('table') }}

If I manually add columns to the "except" parameter, it works, but not with the variable. I tried {{ exclude columns }} as well and same result.



Solution 1:[1]

You have to add quotation marks around the column names, otherwise Jinja will treat them as variables and fails silently, so the results will be a list of 3 None.

{% set exclude_columns = ["col1", "col2", "col3"] %}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dauros