What if you could update massive data tables in seconds without reloading everything?
Why Incremental strategies (append, merge, delete+insert) in dbt? - Purpose & Use Cases
Imagine you have a huge spreadsheet that keeps growing every day with new sales data. Every time you want to update your report, you open the file, scroll through thousands of rows, and try to add only the new sales without messing up the old data.
Doing this by hand is slow and tiring. You might accidentally add duplicate rows or miss some updates. It's easy to make mistakes, and fixing them takes even more time. Plus, as the data grows, the process becomes almost impossible to manage manually.
Incremental strategies in dbt let you update your data automatically and smartly. Instead of reloading everything, you add only new rows (append), update existing ones (merge), or replace changed parts (delete+insert). This saves time, reduces errors, and keeps your data fresh and accurate.
Open spreadsheet, copy new rows, paste at bottom, check for duplicates{{ config(materialized='incremental') }}
{% if is_incremental() %}
-- merge new data with existing table
{% else %}
-- load full data
{% endif %}It enables fast, reliable updates to large datasets without reprocessing everything, making data workflows efficient and scalable.
A retail company uses incremental strategies to update daily sales data in their warehouse. Instead of reloading all sales every day, they append only new transactions and merge updates for returns or corrections, keeping reports accurate and timely.
Manual updates are slow and error-prone for growing data.
Incremental strategies add or update only changed data automatically.
This approach saves time and keeps data accurate and fresh.
Practice
Solution
Step 1: Understand the append strategy
The append strategy adds only new rows to the existing table without changing any existing data.Step 2: Compare with other strategies
Merge updates existing rows and adds new ones; delete+insert replaces matching rows; truncate removes all data first.Final Answer:
append -> Option CQuick Check:
append = add new rows only [OK]
- Confusing merge with append
- Thinking delete+insert only adds rows
- Assuming truncate is an incremental strategy
Solution
Step 1: Identify correct config keys for incremental merge
dbt requires materialized='incremental' and incremental_strategy='merge' to use merge strategy.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'.Final Answer:
config(materialized='incremental', incremental_strategy='merge') -> Option DQuick Check:
incremental_strategy='merge' with materialized='incremental' [OK]
- Using wrong materialized type
- Misspelling incremental_strategy key
- Confusing strategy key name
select id, value from source_table where updated_at > (select max(updated_at) from {{ this }})What will happen when this model runs?
Solution
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 }}).Step 2: Understand merge behavior
Merge updates existing rows with matching keys and inserts new rows. The filter ensures only changed rows are processed.Final Answer:
Rows with matching id are updated or inserted based on updated_at filter -> Option BQuick Check:
merge updates/inserts filtered rows [OK]
- Thinking it replaces entire table
- Assuming only new rows are appended
- Ignoring the filter condition effect
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?
Solution
Step 1: Recall delete+insert requirements
Delete+insert requires a unique_key config to identify rows to delete before insert.Step 2: Analyze error cause
Missing unique_key causes dbt to error because it cannot identify which rows to delete.Final Answer:
You did not specify the unique_key config required for delete+insert -> Option AQuick Check:
delete+insert needs unique_key [OK]
- Ignoring unique_key requirement
- Assuming delete+insert works without keys
- Confusing append with delete+insert
Solution
Step 1: Analyze data update needs
The table has new sales and corrections, so existing rows need updates and new rows need inserts.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.Final Answer:
merge, because it updates existing rows and adds new ones -> Option AQuick Check:
merge = update + insert for corrections and new data [OK]
- Choosing append and missing updates
- Thinking delete+insert always best
- Ignoring performance of full refresh
Ready to prove it?
Pass the test and this pattern moves unknown
