Skip to main content
The merge method uses your database’s MERGE statement (or equivalent) to update existing records and insert new ones. This method provides the most control over how your incremental model is updated but requires more computational resources.

When to Use Merge Method

  • Tables requiring both inserts and updates
  • When data consistency is critical
  • When specific columns need updating
  • For maintaining referential integrity

Advantages and Trade-offs


Example Implementation

In this example:
  • unique_key identifies which records should be updated
  • The WHERE clause in the is_incremental() block filters for new records
  • Existing records with matching event_id values will be updated
  • New records will be inserted

Fine-Tuning Merge Operations

You can precisely control which columns are updated during merge operations:
This configuration gives you fine-grained control over the merge process.

Step By Step Guide: Merge Method Implementation

Let’s see how the merge method works with a practical example. Step 1: Initial Setup and Testing First, create the staging model:
Run staging model:
Verify staging data in Snowflake:
Expected Result:
Create the incremental model:
Run incremental model:
The result should match the staging model (3 rows). Step 2: Testing Merge Method Update staging model with changes:
Run staging model:
Verify staging data:
Expected Result:
Run incremental model:
Verify incremental model:
Expected Result:
Notice that record with ID 1 was updated with the new status and amount, while new record with ID 4 was inserted. Records with IDs 2 and 3 remained unchanged as they weren’t in the staging data.

Common Issues and Solutions

The merge method offers the most flexibility for incremental models, but comes with higher computational costs. Consider it your default choice unless you have specific performance requirements or data characteristics that favor another method.