Bird
0
0

Identify the error in this dbt for loop snippet:

medium📝 Debug Q14 of 15
dbt - Jinja in dbt
Identify the error in this dbt for loop snippet:
{% for col in columns %}SELECT {{ col }} FROM users{% endfor %}

Assuming columns = ['id', 'name'].
AWrong loop syntax with {{ }} instead of {% %}
BMissing UNION ALL or separator between SELECT statements
CIncorrect variable name inside the loop
DLoop variable should be capitalized
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop output

    The loop outputs two SELECT statements back to back without any separator.
  2. Step 2: Identify missing SQL syntax

    Without UNION ALL or a separator, the SQL is invalid and will cause errors.
  3. Final Answer:

    Missing UNION ALL or separator between SELECT statements -> Option B
  4. Quick Check:

    Multiple SELECTs need UNION ALL [OK]
Quick Trick: Add UNION ALL between selects in loops [OK]
Common Mistakes:
MISTAKES
  • Forgetting to add UNION ALL
  • Using wrong loop syntax
  • Misnaming variables inside loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes