Brief
Keep two successive versions of a label without gaps or overlaps and find the one valid at a chosen time.
Voss shows a screenshot of the current entry, only SHELL-02, and claims the registry never named the prototype. Mara retrieves the earlier L1 version. Imani asks you to prepare a practice chronology without altering this evidence: L1 starts April 1 and the change to L2 applies April 12 at 20:00 UTC. The dossier deadline is fictional; no countdown blocks this lesson.
Your mission
- Write both complete history rows with their [start, end) periods.
- Explain what an update that overwrites L1 would do instead of creating L2.
- Explain BEGIN and COMMIT around closing one version and opening the next.
- Name two checks needed before using this history in a report.
How to check your work
- L1 ends at 20:00 exclusive; L2 begins at 20:00 inclusive and remains open.
- Overwriting L1 loses the old description.
- The two writes should be committed together.
- One current version and no overlapping period or unexplained gap.
Course example
CREATE TABLE label_history (
version_id TEXT PRIMARY KEY,
vehicle_label TEXT NOT NULL,
physical_asset TEXT NOT NULL,
valid_from TEXT NOT NULL,
valid_to TEXT,
CHECK (valid_to IS NULL OR valid_from < valid_to),
UNIQUE (vehicle_label, valid_from)
);
INSERT INTO label_history VALUES
('L1', 'NOCTIS-01', 'PROTOTYPE-01', '2026-04-01T00:00:00Z', NULL);
BEGIN;
UPDATE label_history
SET valid_to = '2026-04-12T20:00:00Z'
WHERE version_id = 'L1' AND valid_to IS NULL;
INSERT INTO label_history VALUES
('L2', 'NOCTIS-01', 'SHELL-02', '2026-04-12T20:00:00Z', NULL);
COMMIT;
SELECT version_id, physical_asset, valid_from, valid_to
FROM label_history
ORDER BY valid_from;
SELECT COUNT(*) AS current_versions
FROM label_history
WHERE vehicle_label = 'NOCTIS-01' AND valid_to IS NULL;