An upsert can accumulate a new count into an existing key. The uniqueness constraint determines which row receives the update.
Worked example
CREATE TABLE totals(k TEXT PRIMARY KEY,n INTEGER);
INSERT INTO totals VALUES('a',3);
INSERT INTO totals VALUES('a',4) ON CONFLICT(k) DO UPDATE SET n=n+excluded.n;
SELECT n FROM totals;Result
[
{
"n": 7
}
]Implementation notes
An increment retried after a timeout can count twice. For externally retried events, keep an event identifier so ingestion can recognize duplicates.
Try it yourself
Apply two increments for the same key and one for another key.
Open the SQL example →Editorial date September 29, 2026 · Published December 6, 2026