TutorialApplies to: Unified engine deployments
Use update, insert, and delete clauses together and observe clause order.
Within a match group, MERGE uses the first qualifying clause. Put narrower rules
first. Only the last clause in a match group may omit its condition. A row stays
unchanged when none of its group’s actions qualify.
Before you start
You need a writable Iceberg catalog with namespace creation, table creation, and
MERGE support. These examples create format-v2 tables in a private namespace.
They use inline data and do not need an external sample dataset.
Choose an unused namespace. The examples use learn_merge_03. Replace it
everywhere if it already exists. In Workbench, select your writable
catalog before running any SQL. Keep that catalog selected throughout the
lesson. Opening an example does not execute it.
Set up the namespace
Run this setup once:
Each example creates a separate table. Run an example’s setup once. To start it
again, remove only that example’s table first, using the cleanup section.
Scripts execute as separate operations; they are not a multi-statement
transaction.
1. Delete flagged customers and insert active ones
Start with these target rows:
Apply the incoming source below:
Check all rows:
Expect these exact rows, in any display order:
2. Apply the first matching clause
Start with these target rows:
Apply the incoming source below:
Check all rows:
Expect these exact rows, in any display order:
3. Reverse the clause order and compare the rows
Start with these target rows:
Apply the incoming source below:
Check all rows:
Expect these exact rows, in any display order:
4. Leave a matching row unchanged when no action qualifies
Start with these target rows:
Apply the incoming source below:
Check all rows:
Expect these exact rows, in any display order:
Change one thing
Start the relevant example again from its original target rows. Drop only that
example table, rerun its CREATE TABLE and INSERT statements, then apply the
changed MERGE. Keep the lesson namespace.
Remove the NOT s.is_deleted condition from the insert clause in the
mixed-actions example. Customer 5 should now be inserted with is_deleted = true.
Check the result
Compare every row and field with the expected tables, including unchanged
customers and the number of copies of each key. A Succeeded status alone is not
the result check. Wait for confirmed publication before reading the target.
Clean up
Remove only the private tables created by this lesson:
Continue
Synchronise a complete source snapshot or review the
MERGE SQL reference.Last modified on November 4, 2026