Bird
0
0

Identify the issue in this dbt for loop snippet:

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

Assuming columns = ['user_id', 'email'].
AThe loop generates multiple SELECT statements without UNION or separator, causing invalid SQL
BThe variable 'columns' is not defined in the loop
CThe syntax for the for loop is incorrect
DThe SELECT statement should use double curly braces around 'columns'
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop output

    The loop outputs multiple SELECT statements consecutively without combining them.
  2. Step 2: Identify SQL validity issue

    Multiple SELECTs without UNION or separator produce invalid SQL.
  3. Step 3: Confirm other options

    Variables and syntax are correct; the problem is missing UNION or separator.
  4. Final Answer:

    The loop generates multiple SELECT statements without UNION or separator, causing invalid SQL -> Option A
  5. Quick Check:

    Multiple SELECTs need UNION or separator [OK]
Quick Trick: Combine multiple SELECTs with UNION or separator [OK]
Common Mistakes:
MISTAKES
  • Not adding UNION between SELECTs
  • Assuming loop syntax is wrong
  • Misunderstanding variable usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes