# column "age" is of type integer but expression is of type text

Source: https://sqlstreak.com/sql/errors/column-is-of-type-integer-but-expression-is-of-type-text · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** You're putting a text value into an integer column. Usually the columns are mismatched (the wrong column on the right-hand side, or INSERT … SELECT columns in a different order); when the text really holds numbers, convert it with `CAST(x AS INTEGER)`.

## The exact messages

- PostgreSQL: `ERROR: column "age" is of type integer but expression is of type text`

## How PostgreSQL prints it

```
ERROR:  column "age" is of type integer but expression is of type text
LINE 1: UPDATE pets SET age = breed WHERE id = 1;
                              ^
HINT:  You will need to rewrite or cast the expression.
```

## Why it happens

### The wrong column on the right

`SET age = breed` copies text into a number column. Check which column you meant.

### INSERT … SELECT in a different order

INSERT matches the SELECT's columns to the target columns by position. A text column landing in an integer position fails.

### Numbers stored as text

An imported column of digits is text. CAST it (after cleaning) before writing it into a numeric column.

## The broken query

```sql
UPDATE pets SET age = breed WHERE id = 1;
SELECT name, age FROM pets WHERE id = 1;
```

## The fix

```sql
UPDATE pets SET age = CAST('4' AS INTEGER) WHERE id = 1;
SELECT name, age FROM pets WHERE id = 1;
```

A number for a number column. When the source is text that holds digits, CAST makes the type explicit, and PostgreSQL accepts it.

| name | age |
| --- | --- |
| Biscuit | 4 |

## What SQLite does instead

SQLite stores the text in the integer column without complaint (its types are only hints), so Beagle becomes a pet's age. The mistake only surfaces later, in sums and comparisons.
