Brief
Create the staging table, load it from a SELECT, correct it, and prove the load is replay-safe. Work in your Postgres sandbox.
Tasks
- CREATE
stg_orderswith:BIGINTPK,NOT NULLcustomer + timestamp, non-negativeCHECKon amount,IF NOT EXISTS. - INSERT..SELECT 2,000 rows from the provided
raw_orders_extractseed (fixture attached) with an explicit column list. - UPDATE the miscoded
status='tset'rows to'test'using SELECT-first discipline (paste both statements). - Replay proof: run your INSERT a second time with
ON CONFLICT DO NOTHINGand show row count unchanged (SELECT COUNT(*)before/after). - ALTER: add nullable
coupon_code TEXTwithIF NOT EXISTS.
Acceptance (deterministic checks before review)
stg_ordersexists with PK + CHECK intact.- Row count == seed count after replay (no duplicates).
coupon_codecolumn present, all NULL.- Both SELECT-first statements pasted alongside each write.
Starter
Fixture raw_orders_extract.csv + skeleton .sql with TODO markers are attached.