← All notes

UPSERT in SQLite

Answer: The syntax follows PostgreSQL.

CREATE TABLE vocab (word TEXT PRIMARY KEY, count INT DEFAULT 1);

INSERT INTO vocab(word) VALUES ('jovial')
  ON CONFLICT(word) DO UPDATE SET count = count + 1;

INSERT INTO phonebook(name, phone) VALUES ('Alice', '555')
  ON CONFLICT(name) DO UPDATE SET phone = excluded.phone
  WHERE excluded.phone <> phonebook.phone;

Rules

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: SQLite (sqlite.org), UPSERT, Public domain (sqlite.org); SQLite (sqlite.org), INSERT, Public domain (sqlite.org).

Cite this

Permanent ID: iil:note:waqakesv

iinventedlight. 2026. "UPSERT in SQLite." iinventedlight Library, iil:note:waqakesv, version of 2026-11-04. https://iinventedlight.com/library/notes/sqlite-upsert/. License: CC-BY-4.0.

@misc{iil_note_waqakesv,
  author = {{iinventedlight}},
  title = {{UPSERT in SQLite}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/sqlite-upsert/},
  note = {Permanent ID iil:note:waqakesv. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/sqlite-upsert.md.