Bird
0
0

Identify the error in this dbt snippet:

medium📝 Debug Q14 of 15
dbt - Jinja in dbt
Identify the error in this dbt snippet:
{% set total = 0 %}
{% for i in range(3) %}
  {% set total = total + i %}
{% endfor %}
{{ total }}
AThe <code>range</code> function is not available in dbt Jinja.
BVariables cannot be updated inside a loop.
CThe loop syntax is incorrect; missing parentheses.
DThe variable <code>total</code> should be declared with <code>var</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Jinja in dbt limitations

    dbt uses Jinja templating, which does not support Python's range() function directly.
  2. Step 2: Identify the error cause

    Using range(3) will cause an error because range is undefined in this context.
  3. Final Answer:

    The range function is not available in dbt Jinja. -> Option A
  4. Quick Check:

    No range() in dbt Jinja [OK]
Quick Trick: Remember: Jinja loops use lists, not Python range() [OK]
Common Mistakes:
MISTAKES
  • Assuming Python functions work in Jinja
  • Trying to update variables inside loops without workarounds
  • Using wrong loop syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes