E0005 column-count-mismatch
Column count doesn't match (INSERT, column aliases, subqueries).
| Code | Name | Category | Default |
|---|---|---|---|
E0005 | column-count-mismatch | correctness | error |
What it reports
- An
INSERTlists a different number of values (orSELECTcolumns) than target columns. - A column alias list names more columns than the relation has:
FROM users AS u(a, b, c, d, e, f),WITH x(a, b) AS (SELECT 1). MySQL and SQLite need exactly one name per column of a CTE or derived table. - A subquery used as a value (
x = (SELECT ...),x IN (SELECT ...)) returns more than one column, or a row ((a, b) IN (SELECT ...),(a, b) = (1, 2, 3)) is compared with a different number of values.
Example
INSERT INTO users (name, email) VALUES ('a');
error[E0005]: INSERT has 1 value(s) but 2 column(s) were specified
--> q.sql:1:13
|
1 | INSERT INTO users (name, email) VALUES ('a');
| ^^^^^
= help: Provide 2 value(s) to match the column list
Fixed:
INSERT INTO users (name, email) VALUES ('a', 'a@example.com');
Notes
Without a column list, the values are compared with all columns of the table. PostgreSQL (and Redshift) accept fewer values there and fill the remaining columns with their defaults, so only too many values are reported; every VALUES row must still have the same length, and a required column left out is reported as E0008. MySQL, SQLite and the other dialects need a value for every column.
Configuring
# sqlsift.toml
[rules]
column-count-mismatch = "warn" # or "off"
Or for a single line: -- sqlsift:disable E0005. The examples use the schema on the Rules page.