# invalid input syntax for type integer: "3 years"

Source: https://sqlstreak.com/sql/errors/invalid-input-syntax-for-type-integer · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** PostgreSQL tried to turn a piece of text into an integer and the text isn't a valid number. Compare with a real number, or clean the text before casting.

## The exact messages

- PostgreSQL: `ERROR: invalid input syntax for type integer: "3 years"`

## How PostgreSQL prints it

```
ERROR:  invalid input syntax for type integer: "3 years"
LINE 2: WHERE age = '3 years';
                    ^
```

## Why it happens

### Comparing a number column with text

`WHERE age = '3 years'`: the quoted value has to become an integer, and it can't.

### Casting messy imported data

`CAST(budget AS integer)` fails on values like `'$120'` or `''`. Strip the junk first and turn empty strings into NULL with `NULLIF(x, '')`.

## The broken query

```sql
SELECT name FROM pets
WHERE age = '3 years';
```

## The fix

```sql
SELECT name FROM pets
WHERE age = 3;
```

Compare numbers with numbers. For messy text columns, see the data-cleaning guide for safe ways to convert them.

| name |
| --- |
| Biscuit |
| Clover |
| Pumpkin |

## What SQLite does instead

SQLite doesn't complain: it compares the text '3 years' with numbers, finds nothing equal and returns zero rows. (And `CAST('abc' AS INTEGER)` silently gives 0.)
