Bird
Raised Fist0
dbtdata~10 mins

Incremental strategies (append, merge, delete+insert) in dbt - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Incremental strategies (append, merge, delete+insert)
Start: New Data Available
↓
Choose Incremental Strategy
↓
Append
↓
Add new
↓
Incremental Table Updated
↓
End
This flow shows how new data is added to an existing table using three strategies: append adds only new rows, merge updates existing rows and adds new ones, and delete+insert removes old data before adding fresh data.
Execution Sample
dbt
select * from source_table
where updated_at > (select max(updated_at) from target_table)
This query selects only new or updated rows from the source to add to the target table incrementally.
Execution Table
StepActionSource DataTarget Table BeforeTarget Table AfterNotes
1Initial target table[A1, A2, A3][A1, A2][A1, A2]Target has 2 rows initially
2Append new rows[A1, A2, A3][A1, A2][A1, A2, A3]A3 appended, no updates
3Merge update A2[A1, A2(updated), A3][A1, A2, A3][A1, A2(updated), A3]A2 row updated, others unchanged
4Delete + Insert all[A1, A2(updated), A3][A1, A2, A3][A1, A2(updated), A3]Old rows deleted, all re-inserted fresh
5End-[A1, A2(updated), A3][A1, A2(updated), A3]Incremental update complete
💡 All new and updated data processed; incremental table is current.
Variable Tracker
VariableStartAfter AppendAfter MergeAfter Delete+InsertFinal
target_table_rows23333
updated_rows00133
deleted_rows00033
Key Moments - 3 Insights
Why does the append strategy not update existing rows?
Because append only adds new rows without checking for existing data, as shown in step 2 of the execution_table where A3 is added but A2 remains unchanged.
How does the merge strategy handle updated rows?
Merge updates existing rows and adds new ones, demonstrated in step 3 where A2 is updated in the target table while A1 and A3 stay the same.
What happens in the delete + insert strategy before adding new data?
All old rows are deleted first, then fresh data is inserted, as seen in step 4 where the target table is cleared and then reloaded with updated rows.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, how many rows does the target table have after append?
A3
B2
C1
D4
💡 Hint
Check the 'Target Table After' column at step 2 in the execution_table.
At which step does the target table get updated with a changed row?
AStep 2
BStep 3
CStep 4
DStep 1
💡 Hint
Look for the step where 'A2(updated)' appears in the 'Target Table After' column.
If we skip deleting old rows, which strategy are we NOT using?
AAppend
BMerge
CDelete + Insert
DAll strategies
💡 Hint
Refer to step 4 where old rows are deleted before inserting new data.
Concept Snapshot
Incremental strategies add new data efficiently:
- Append: add only new rows
- Merge: update existing + add new
- Delete + Insert: remove old, then add fresh
Choose based on data freshness and update needs.
Full Transcript
Incremental strategies in dbt help update tables efficiently. Append adds only new rows without changing existing ones. Merge updates existing rows and adds new ones. Delete plus insert removes all old data before inserting fresh data. This process keeps data current without full reloads. The execution table shows how the target table changes step-by-step with each strategy. Variables track rows added, updated, or deleted. Understanding these helps choose the right method for your data pipeline.

Practice

(1/5)
1. Which incremental strategy in dbt only adds new rows without modifying existing ones?
easy
A. delete+insert
B. merge
C. append
D. truncate

Solution

  1. Step 1: Understand the append strategy

    The append strategy adds only new rows to the existing table without changing any existing data.
  2. Step 2: Compare with other strategies

    Merge updates existing rows and adds new ones; delete+insert replaces matching rows; truncate removes all data first.
  3. Final Answer:

    append -> Option C
  4. Quick Check:

    append = add new rows only [OK]
Hint: Append means add new rows only, no updates [OK]
Common Mistakes:
  • Confusing merge with append
  • Thinking delete+insert only adds rows
  • Assuming truncate is an incremental strategy
2. Which of the following is the correct syntax to define an incremental model using the merge strategy in dbt?
easy
A. config(materialized='incremental', incremental_strategy='append')
B. config(materialized='incremental', strategy='merge')
C. config(materialized='table', incremental_strategy='merge')
D. config(materialized='incremental', incremental_strategy='merge')

Solution

  1. Step 1: Identify correct config keys for incremental merge

    dbt requires materialized='incremental' and incremental_strategy='merge' to use merge strategy.
  2. Step 2: Check each option for correctness

    config(materialized='incremental', incremental_strategy='append') uses 'append' strategy, not merge; config(materialized='table', incremental_strategy='merge') uses materialized='table' which is not incremental; config(materialized='incremental', strategy='merge') uses wrong key 'strategy'.
  3. Final Answer:

    config(materialized='incremental', incremental_strategy='merge') -> Option D
  4. Quick Check:

    incremental_strategy='merge' with materialized='incremental' [OK]
Hint: Use incremental_strategy='merge' inside config() for merge [OK]
Common Mistakes:
  • Using wrong materialized type
  • Misspelling incremental_strategy key
  • Confusing strategy key name
3. Given this dbt incremental model snippet using merge strategy:
select id, value from source_table where updated_at > (select max(updated_at) from {{ this }})

What will happen when this model runs?
medium
A. Only new rows with updated_at greater than max in target are added
B. Rows with matching id are updated or inserted based on updated_at filter
C. All rows from source_table replace the target table
D. No rows are added or updated because filter excludes all

Solution

  1. Step 1: Understand the filter condition

    The query selects rows from source_table where updated_at is greater than the max updated_at in the target table ({{ this }}).
  2. Step 2: Understand merge behavior

    Merge updates existing rows with matching keys and inserts new rows. The filter ensures only changed rows are processed.
  3. Final Answer:

    Rows with matching id are updated or inserted based on updated_at filter -> Option B
  4. Quick Check:

    merge updates/inserts filtered rows [OK]
Hint: Merge updates or inserts rows filtered by updated_at [OK]
Common Mistakes:
  • Thinking it replaces entire table
  • Assuming only new rows are appended
  • Ignoring the filter condition effect
4. You wrote this incremental model using delete+insert strategy:
config(materialized='incremental', incremental_strategy='delete+insert')

select * from source_table

But the model fails with an error about missing unique key. What is the likely cause?
medium
A. You did not specify the unique_key config required for delete+insert
B. The source_table is empty
C. delete+insert strategy does not support incremental models
D. You must use append strategy instead

Solution

  1. Step 1: Recall delete+insert requirements

    Delete+insert requires a unique_key config to identify rows to delete before insert.
  2. Step 2: Analyze error cause

    Missing unique_key causes dbt to error because it cannot identify which rows to delete.
  3. Final Answer:

    You did not specify the unique_key config required for delete+insert -> Option A
  4. Quick Check:

    delete+insert needs unique_key [OK]
Hint: Always set unique_key for delete+insert strategy [OK]
Common Mistakes:
  • Ignoring unique_key requirement
  • Assuming delete+insert works without keys
  • Confusing append with delete+insert
5. You have a large sales table that updates daily with new sales and corrections to existing sales records. Which incremental strategy should you choose in dbt to efficiently update the table without full reloads?
hard
A. merge, because it updates existing rows and adds new ones
B. delete+insert, because it deletes all rows and inserts fresh data
C. append, because it only adds new rows
D. full refresh, because incremental strategies are not suitable

Solution

  1. Step 1: Analyze data update needs

    The table has new sales and corrections, so existing rows need updates and new rows need inserts.
  2. Step 2: Match strategy to needs

    Append only adds new rows, so it won't update corrections. Delete+insert replaces matching rows but can be costly. Merge efficiently updates and inserts rows incrementally.
  3. Final Answer:

    merge, because it updates existing rows and adds new ones -> Option A
  4. Quick Check:

    merge = update + insert for corrections and new data [OK]
Hint: Use merge for updates plus new rows efficiently [OK]
Common Mistakes:
  • Choosing append and missing updates
  • Thinking delete+insert always best
  • Ignoring performance of full refresh
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard