SQL error
datatype mismatch (SQLite)
Updated · Tested on PostgreSQL 18.6 and SQLite 3.54.1 (results generated , re-checked on every release)
Short answer
SQLite is relaxed about types, with two exceptions: an INTEGER PRIMARY KEY column only holds integers, and a table created STRICT checks every column. Put a whole number in the id, or convert the value first.
The exact messages
- PostgreSQLERROR: invalid input syntax for type integer: "C-99"
- SQLitedatatype mismatch
How to read this message
This is what PostgreSQL 18.6 prints for the broken query below, the way psql shows it. LINE gives the line it was reading when it gave up, and the ^ marks the exact spot.
ERROR: invalid input syntax for type integer: "C-99"
LINE 2: VALUES ('C-99', 'Ann Lee', 'Oslo', '2026-03-01');
^SQLite 3.54.1 reports the same mistake as datatype mismatch, with no line number: look for the word or column it names.
Why it happens
Text in an INTEGER PRIMARY KEY
In SQLite, INTEGER PRIMARY KEY is the row's own id (the rowid), so it must be an integer. Other INTEGER columns would quietly store the text.
A STRICT table
Tables created with STRICT reject a value of the wrong type in any column, with a message naming the column. Ordinary tables accept it.
An imported id with letters
Codes like C-99 look like ids but aren't numbers. Keep them in a TEXT column and let the integer id be generated.
Reproduce it, then fix it
Both queries run on a real database in your browser. Switch dialects to compare.
INSERT INTO customers (id, name, city, joined_on)
VALUES ('C-99', 'Ann Lee', 'Oslo', '2026-03-01');
SELECT * FROM customers WHERE name = 'Ann Lee';INSERT INTO customers (id, name, city, joined_on)
VALUES (99, 'Ann Lee', 'Oslo', '2026-03-01');
SELECT * FROM customers WHERE id = 99;A whole number for the id works in both databases. PostgreSQL rejects the text for its own reason: it can't read C-99 as an integer.
The fix returns, PostgreSQL: 1 row
| id | name | city | joined_on |
|---|---|---|---|
| 99 | Ann Lee | Oslo | 2026-03-01 |
The fix returns, SQLite: 1 row
| id | name | city | joined_on |
|---|---|---|---|
| 99 | Ann Lee | Oslo | 2026-03-01 |
Experiment with it: PostgreSQL playground·SQLite playground
Other forms of this mistake
Each one was run when this page was built; the result is what the engine really does.
CREATE TABLE scores (player TEXT, points INTEGER) STRICT; INSERT INTO scores VALUES ('Ann', 'ten'); SELECT * FROM scores;SQLitecannot store TEXT value in INTEGER column scores.points
A STRICT table says which column refused the value.
CREATE TABLE scores (player TEXT, points INTEGER); INSERT INTO scores VALUES ('Ann', 'ten'); SELECT player, points, typeof(points) FROM scores;SQLiteRuns without an error
Without STRICT, SQLite stores 'ten' in the INTEGER column as text, without a word.
Official documentation
Stop hitting this error
Practise the concept behind it in a five-minute lesson, or read the full guide: SQL CREATE TABLE, constraints and views.