# datatype mismatch (SQLite)

Source: https://sqlstreak.com/sql/errors/datatype-mismatch · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**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

- PostgreSQL: `ERROR: invalid input syntax for type integer: "C-99"`
- SQLite: `datatype mismatch`

## How PostgreSQL prints it

```
ERROR:  invalid input syntax for type integer: "C-99"
LINE 2: VALUES ('C-99', 'Ann Lee', 'Oslo', '2026-03-01');
                ^
```

## 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.

## The broken query

```sql
INSERT INTO customers (id, name, city, joined_on)
VALUES ('C-99', 'Ann Lee', 'Oslo', '2026-03-01');
SELECT * FROM customers WHERE name = 'Ann Lee';
```

## The fix

```sql
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.

| id | name | city | joined_on |
| --- | --- | --- | --- |
| 99 | Ann Lee | Oslo | 2026-03-01 |
