Skip to main content
TutorialApplies to: Unified engine deployments
Compare physical deletion with a stored deletion marker and reject an older update. These examples define an event contract: id is the customer key; version increases for each change to that key; name and balance contain the full new values; is_deleted marks a delete event. The physical-delete example assumes ordered input. A tombstone is a stored deletion marker. Keeping that marker and its version lets a later merge reject an older event instead of inserting the customer again. Use the preceding deduplication lesson when a batch contains several events for one key.

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_07. 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. Apply ordered create, update, and delete events

Start with these target rows:
Apply the incoming source below:
Check all rows:
Expect these exact rows, in any display order: Physical deletion removes the stored row and its version. With out-of-order input, an older later insert could recreate that key. The next example keeps the deletion version.

2. Keep the delete version to reject a stale update

Start with these target rows:
Apply the incoming source below:
Check all rows:
Expect these exact rows, in any display order: Now apply the older event:
The result must still be: Customer 2 remains in storage with is_deleted = true and version 3. Consumers should filter out deletion markers. Keeping the version prevents the older version 2 event from making it active again.

Change one thing

Continue from the existing tombstone example without rerunning its setup. After the tombstone example, send an active version 4 for customer 2. The newer event should make that customer active again. A version 2 event should remain ignored.

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

Run MERGE incrementally or review the MERGE SQL reference.
Last modified on November 4, 2026