When to Use Delete+Insert Method
- Batch updates where most records change
- When merge performance becomes a bottleneck
- Simpler change patterns
- Large-scale updates
- When most fields in each record need updating
Advantages and Trade-offs
Example Implementation
- Records matching the
WHEREcondition will first be deleted - Then all new/updated records will be inserted
- This is more efficient than merge when most fields need updating
How It Works
When you run a delete+insert incremental model, dbt:- Creates a temporary table with all the data from your query
- Identifies records in the target table that match the incremental filter condition
- Deletes those matching records from the target table
- Inserts all records from the temporary table into the target table
Step By Step Guide: Delete+Insert Method Implementation
Let’s see how the delete+insert method works with a practical example. Initial Setup Follow the same initial setup as the Merge Method example, creating the staging model and first version of the incremental model. Testing Delete+Insert Method- Update incremental model config (keep same staging data):
- Update staging model with changes:
- Run staging model:
- Run incremental model:
- Verify in Snowflake:
Best Practices for Delete+Insert
- Use with Batch Processing - This method works best when processing logical batches of data (like daily updates)
- Optimize the Filter Condition - Choose an incremental filter that selects all records that might need updating but minimizes unnecessary processing
- Consider Performance Impact - The delete operation affects indexes and can cause fragmentation; plan your maintenance accordingly
- Pair with Partitioning - If your database supports it, partitioning can make delete+insert operations more efficient