Open lesson

Mission: the doubled transfer in the report

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

Brief

Replay a batch already loaded without doubling its events, while flagging a repeated identifier whose values disagree.

Voss points to four report rows as if B1 were delivered twice by independent sources. Imani knows raw B1 contained E7 and TRANSFER-7 and that the pipeline replayed B1 after a stop. Mara gives you an empty practice table with unique event_id. A late TRANSFER-7 also says vehicle = TEST-02 instead of NOCTIS-01. The team needs that contradiction reported.

Your mission

  1. Give the row count after the first B1 load and after an identical replay using ON CONFLICT.
  2. Write the clause that prevents a second E7 row.
  3. Explain what to do when TRANSFER-7 returns with another vehicle but the same ID.
  4. Give the reference row count after B2 adds new E9, and say what that count cannot prove.

How to check your work

  • First load: 2 rows; identical replay: still 2.
  • The clause is ON CONFLICT (event_id) DO NOTHING.
  • Keep and flag conflicting content instead of silently dropping it.
  • New E9 makes 3 rows; the count proves neither authorship nor authenticity.

Course example

CREATE TABLE events (
    event_id TEXT PRIMARY KEY,
    vehicle TEXT NOT NULL,
    source_file TEXT NOT NULL
);
INSERT INTO events VALUES ('E7', 'NOCTIS-01', 'gate-page1.json');
INSERT INTO events VALUES ('TRANSFER-7', 'NOCTIS-01', 'vendor-page2.json');

INSERT INTO events VALUES ('E7', 'NOCTIS-01', 'gate-page1.json')
ON CONFLICT (event_id) DO NOTHING;
INSERT INTO events VALUES ('TRANSFER-7', 'NOCTIS-01', 'vendor-page2.json')
ON CONFLICT (event_id) DO NOTHING;

SELECT COUNT(*) AS stored_rows FROM events;
SELECT event_id, vehicle, source_file FROM events ORDER BY event_id;

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with -- are task reminders. SQL ignores them. Write your query beneath them.

SQL console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.sql

Current editor source. Inspection shows your current edits.

-- Give the row count after the first B1 load and after an identical replay using ON CONFLICT.
-- Write the clause that prevents a second E7 row.
-- Explain what to do when TRANSFER-7 returns with another vehicle but the same ID.
-- Give the reference row count after B2 adds new E9, and say what that count cannot prove.

exemple.sql

Declarative lesson asset; this is not a file created in the Python filesystem.

CREATE TABLE events (
    event_id TEXT PRIMARY KEY,
    vehicle TEXT NOT NULL,
    source_file TEXT NOT NULL
);
INSERT INTO events VALUES ('E7', 'NOCTIS-01', 'gate-page1.json');
INSERT INTO events VALUES ('TRANSFER-7', 'NOCTIS-01', 'vendor-page2.json');

INSERT INTO events VALUES ('E7', 'NOCTIS-01', 'gate-page1.json')
ON CONFLICT (event_id) DO NOTHING;
INSERT INTO events VALUES ('TRANSFER-7', 'NOCTIS-01', 'vendor-page2.json')
ON CONFLICT (event_id) DO NOTHING;

SELECT COUNT(*) AS stored_rows FROM events;
SELECT event_id, vehicle, source_file FROM events ORDER BY event_id;