# UNION types text and integer cannot be matched

Source: https://sqlstreak.com/sql/errors/union-types-cannot-be-matched · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** UNION stacks columns by position, so each position needs the same type on both sides. A text column lined up with an integer column usually means the columns are in the wrong order or the wrong one was picked.

## The exact messages

- PostgreSQL: `ERROR: UNION types text and integer cannot be matched`

## How PostgreSQL prints it

```
ERROR:  UNION types text and integer cannot be matched
LINE 3: SELECT id FROM staff;
               ^
```

## Why it happens

### Columns in a different order

`SELECT name, id … UNION SELECT id, name …` puts ids under names. UNION matches by position, never by column name.

### The wrong column on one side

Picking `id` where you meant `name`. Read both SELECT lists side by side.

### You really need mixed values

Then convert explicitly, `CAST(id AS TEXT)`, so the result column is text on both sides.

## The broken query

```sql
SELECT name FROM customers
UNION
SELECT id FROM staff;
```

## The fix

```sql
SELECT name FROM customers
UNION
SELECT name FROM staff;
```

Text under text: both sides now return names.

| name |
| --- |
| Lia Moreau |
| Ben Carter |
| Diego Santos |
| Ellie Park |
| Maya Ortiz |
| Yuki Tanaka |

(6 of 18 rows)

## What SQLite does instead

SQLite stacks the values anyway, so names and numbers end up mixed in one column. No error, just a result that makes no sense.
