Skip to content
Advertisement

How do I loop through alll columns using Jinja in DBT?

I want to iterate over all the columns using dbt.

Advertisement

Answer

I think the star macro from the dbt-utils package + some for-loop logic might help you here? This depends on the exact use case and warehouse you’re using (as pointed out in the comments).

The star macro generates a list of columns in the table provided.

So a possible approach would be something along the lines of:

{% for col in [{{ dbt_utils.star(ref('my_model')) }}] %}
...operation...
{% endfor %}

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement