Bird
0
0

Given the dbt model code:

medium📝 Predict Output Q13 of 15
dbt - Jinja in dbt
Given the dbt model code:
SELECT * FROM orders WHERE order_date >= '{{ start_date }}' {% if is_active %}AND status = 'active'{% endif %}

What will be the output SQL if start_date = '2023-01-01' and is_active = False?
ASELECT * FROM orders WHERE order_date >= '2023-01-01' AND status = 'active'
BSELECT * FROM orders WHERE order_date >= '2023-01-01' OR status = 'active'
CSELECT * FROM orders WHERE order_date >= '2023-01-01'
DSELECT * FROM orders WHERE order_date >= start_date
Step-by-Step Solution
Solution:
  1. Step 1: Substitute the variable start_date

    The variable start_date is replaced with '2023-01-01' inside quotes.
  2. Step 2: Evaluate the if condition with is_active = False

    The condition {% if is_active %} is false, so the AND clause is omitted.
  3. Final Answer:

    SELECT * FROM orders WHERE order_date >= '2023-01-01' -> Option C
  4. Quick Check:

    False if-block = no AND clause [OK]
Quick Trick: If condition false means skip that SQL part [OK]
Common Mistakes:
MISTAKES
  • Including AND clause when condition is false
  • Not replacing variables with values
  • Confusing OR with AND in conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes