How can an importer preserve the first payload when an event is replayed?

ON CONFLICT(key) DO NOTHING retains the existing row and skips the conflicting insert for that unique key.

SQLite example and interpretation

Event one arrives with A and then B. A first-arrival policy keeps A. Compare payloads separately if corrections or conflicting source records must be detected.

CREATE TABLE e(id INTEGER PRIMARY KEY,v TEXT);
INSERT INTO e VALUES(1,'A');
INSERT INTO e VALUES(1,'B') ON CONFLICT(id) DO NOTHING;
SELECT v FROM e;

Result [["A"]]

中文

怎样让导入器重放同一事件时保留原始内容?

ON CONFLICT(键) DO NOTHING 在指定唯一键冲突时保留旧行,并跳过该次插入。

SQLite 示例与适用条件

同一事件 id=1 先后携带 A 与 B,先到的 A 留下。需要发现上游篡改或纠错时,还要对比两份负载。

CREATE TABLE e(id INTEGER PRIMARY KEY,v TEXT);
INSERT INTO e VALUES(1,'A');
INSERT INTO e VALUES(1,'B') ON CONFLICT(id) DO NOTHING;
SELECT v FROM e;

结果 [["A"]]

References / 参考来源

Keep reading / 继续阅读