Append Strategy in Incremental dbt: What It Is and How It Works
append strategy in incremental dbt means adding only new rows to a target table without updating or deleting existing data. It is used when your data source only grows by new records, making incremental loads faster and simpler by just appending new data.How It Works
The append strategy in dbt incremental models works by adding new rows from your source data to the existing target table without changing or removing any old rows. Imagine you have a notebook where you write down new daily sales records. Instead of rewriting the whole notebook every day, you just add the new sales at the end. This is exactly how the append strategy works—it only adds new data.
This approach is efficient when your data source only grows and does not change past records. dbt checks for new rows based on a unique key or timestamp and inserts them into the target table. It does not update or delete any existing rows, which makes the process faster and simpler.
Example
This example shows a simple dbt model using the append strategy to add new rows incrementally.
{{ config(
materialized='incremental',
incremental_strategy='append'
) }}
select * from source_table
{% if is_incremental() %}
where created_at > (select max(created_at) from {{ this }})
{% endif %}When to Use
Use the append strategy when your source data only adds new records and never updates or deletes old ones. For example, log files, event tracking data, or daily snapshots where each row is unique and never changes.
This strategy is ideal when you want fast incremental loads without the complexity of handling updates or deletes. It reduces processing time and resource use because dbt only inserts new rows.
Key Points
- The append strategy only adds new rows, no updates or deletes.
- It is best for data that only grows, like logs or event data.
- It makes incremental loads faster and simpler.
- Requires a way to identify new rows, often a timestamp or unique ID.