Bird
0
0

What will happen if you run this dbt model with is_incremental() logic and the target table is empty?

medium📝 Predict Output Q5 of 15
dbt - Incremental Models
What will happen if you run this dbt model with is_incremental() logic and the target table is empty?
{% if is_incremental() %}
  SELECT * FROM source_table WHERE id > (SELECT MAX(id) FROM {{ this }})
{% else %}
  SELECT * FROM source_table
{% endif %}
AAll rows from source_table will be inserted
BNo rows will be inserted because MAX(id) returns NULL
COnly rows with id greater than NULL will be inserted
DThe model will fail with a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand MAX(id) on empty table

    MAX(id) returns NULL if the target table is empty.
  2. Step 2: Evaluate the WHERE clause with NULL

    Comparing id > NULL yields false, so no rows match.
  3. Final Answer:

    No rows will be inserted because MAX(id) returns NULL -> Option B
  4. Quick Check:

    MAX on empty = NULL, comparison fails [OK]
Quick Trick: MAX on empty table returns NULL, blocking incremental inserts [OK]
Common Mistakes:
MISTAKES
  • Assuming NULL comparison returns true
  • Expecting all rows to insert on empty table
  • Thinking model will error out

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes