Open this example in the interactive library
Source code
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;
Sample output
[
{
"n": 7
}
]