Bird
0
0

An incremental model uses this SQL:

medium📝 Debug Q7 of 15
dbt - Incremental Models
An incremental model uses this SQL:
select * from source_table where id > (select max(id) from {{ this }})

After running dbt run the first time, you notice no rows in the target table. What is the most likely cause?
AThe incremental config is missing in the model.
BThe max(id) subquery returns NULL on empty table, causing no rows to be inserted.
CThe source_table has duplicate ids.
Ddbt does not support incremental models with subqueries.
Step-by-Step Solution
Solution:
  1. Step 1: Understand max(id) behavior on empty table

    If the target table is empty, max(id) returns NULL, so the filter becomes id > NULL, which is false/unknown, causing no rows to be selected.
  2. Step 2: Explain the cause

    Without handling NULL (e.g., with COALESCE(max(id), 0)), the model inserts no rows on the first run.
  3. Final Answer:

    The max(id) subquery returns NULL on empty table, causing no rows to be inserted. -> Option B
  4. Quick Check:

    First run max() NULL causes no inserts [OK]
Quick Trick: Use COALESCE on max() to handle empty table [OK]
Common Mistakes:
MISTAKES
  • Not handling NULL result from max() on empty table
  • Assuming missing config causes no inserts
  • Blaming source_table for being empty

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes