# 20: NUMBER_OF_COLUMNS_DOESNT_MATCH (code 20)

> The rows being inserted have a different column count than the statement or the target table expects.

Source: https://sqlly.app/errors/clickhouse/number-of-columns-doesnt-match
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Error code: `20`
- Name: `NUMBER_OF_COLUMNS_DOESNT_MATCH`
- Category: Formats and input data

Error message:

```text
Number of columns doesn't match
```

## What it means

`NUMBER_OF_COLUMNS_DOESNT_MATCH` (20) fires while INSERT data is parsed, when a row's value count disagrees with the column list or the table: a VALUES tuple with the wrong arity, a CSV or JSONEachRow row with missing or extra fields, or an INSERT ... SELECT projection that differs from the target list.

## Common causes

- A hand written INSERT has a different number of values per tuple.
- A CSV or JSONEachRow row gained or lost fields, often after a schema edit on either side.
- INSERT INTO t (a, b) SELECT ... selects a different number of columns.

## How to fix it

1. Compare the target schema against the file header before importing.

   ```sql
   DESCRIBE TABLE my_table;
   ```
2. Name every column explicitly so positional drift becomes an error you can read.

   ```sql
   INSERT INTO my_table (id, name) VALUES (1, 'a');
   ```
3. Eyeball the first rows of a suspect file with the same format the import uses.

   ```sql
   SELECT * FROM file('data.csv', CSVWithNames) LIMIT 5;
   ```

## Reproduce it safely

VALUES binds positionally, so a single missing value is enough; file formats report the first bad row instead.

```sql
CREATE TABLE scratch_h (a UInt32, b String) ENGINE = MergeTree ORDER BY a; then INSERT INTO scratch_h VALUES (1) returns code 20.
```

## How SQLly helps

SQLly's CSV import previews parsed rows with their row and column numbers and rejects the file before it inserts anything.

## Questions

### A CSV row has too many fields?

An extra CSV field raises 117 INCORRECT_DATA (Expected end of line). A short row raises 27 CANNOT_PARSE_INPUT_ASSERTION_FAILED. Neither is code 20. A trailing comma on a two-column row was accepted silently in 26.9, so check the loaded rows.

### Why did this break after we added a column?

INSERT without a column list binds values positionally to every table column. Appending a column with ADD COLUMN makes an old-width VALUES tuple fail with code 62. A column added AFTER a position can shift values silently when the tuple width still matches. Always list columns explicitly.

## Related errors

- [`53`](https://sqlly.app/errors/clickhouse/type-mismatch): TYPE_MISMATCH (code 53)
- [`16`](https://sqlly.app/errors/clickhouse/no-such-column-in-table): NO_SUCH_COLUMN_IN_TABLE (code 16)

The code and message text are from the [ClickHouse documentation (system.errors)](https://clickhouse.com/docs/en/operations/system-tables/errors).
