runtime
CRM + ERP Integration · milestone 09 / 12

milestone 9/12 Idempotent incremental UPSERT & stale updates

Repeat incremental updates safely and reject stale changes.

CRM + ERP Integration · Follow extraction reconciliation, authoritative integration, date quarantine, quality gates, stable keys, replay-safe loads, and atomic promotion. Finish with a customer-grain capstone and field-level lineage.

approach

An incremental load inserts new keys and updates only newer source versions. Replay the same batch and the final rows must stay the same. A timestamp watermark alone can miss late records or equal timestamps; real pipelines need a defined tie-breaker/replay window, delete handling, and transactional checkpointing.

worked-example.sql
INSERT INTO current_people(customer_id,name,updated_at)
SELECT customer_id,name,updated_at
FROM incoming_people
WHERE 1 ON CONFLICT(customer_id) DO
UPDATE
SET name=excluded.name,updated_at=excluded.updated_at
WHERE excluded.updated_at>current_people.updated_at;
INSERT INTO current_people(customer_id,name,updated_at)
SELECT customer_id,name,updated_at
FROM incoming_people
WHERE 1 ON CONFLICT(customer_id) DO
UPDATE
SET name=excluded.name,updated_at=excluded.updated_at
WHERE excluded.updated_at>current_people.updated_at;
SELECT customer_id,name,updated_at
FROM current_people;

data for this milestone

incoming_people3 columns · 3 rows
customer_idtext · keynametextupdated_attext
C001Alice New2025-02-01
C002Ben stale2024-01-01
C006Finn2025-02-02

all 3 rows

current_people4 columns · 2 rows
customer_keyinteger · keycustomer_idtextnametextupdated_attext
1C001Alice Nguyen2025-01-05
2C002Ben2025-01-02

all 2 rows

challenge 1

Apply incoming_people to current_people with INSERT ON CONFLICT(customer_id) DO UPDATE only if the incoming updated_at is newer.

Apply that same batch twice.

Return customer_id,name,updated_at.

what to return

Columns
customer_idnameupdated_at in this order
Rows
any order
Also checked
TEMP / table changes from your script
challenge-1.sql
 
3 steps left · check both queries and pass the concept checkOpen the reportNext milestone
Idempotent incremental UPSERT & stale updates — CRM + ERP Integration · Runtime