Bird
0
0

This dbt model uses is_incremental() but does not insert new rows during incremental runs:

medium📝 Debug Q7 of 15
dbt - Incremental Models
This dbt model uses is_incremental() but does not insert new rows during incremental runs:
{% if is_incremental() %}
  SELECT * FROM source_table WHERE updated_at < (SELECT MAX(updated_at) FROM {{ this }})
{% else %}
  SELECT * FROM source_table
{% endif %}

What is the problem?
AThe else block should be inside the if block
BThe WHERE condition selects older rows, so no new rows are added
CThe model is missing a primary key
Dis_incremental() returns false always
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the WHERE clause logic

    The condition selects rows with updated_at less than max existing, i.e., older rows.
  2. Step 2: Understand incremental load goal

    Incremental loads should add newer rows, so this condition prevents inserts.
  3. Final Answer:

    The WHERE condition selects older rows, so no new rows are added -> Option B
  4. Quick Check:

    Incremental filter must select newer rows [OK]
Quick Trick: Use > not < to select new rows in incremental loads [OK]
Common Mistakes:
MISTAKES
  • Using less than instead of greater than in WHERE
  • Misplacing else block
  • Assuming is_incremental() always true

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes