SQL errors, explained and fixed
Paste-worthy answers to the error messages you actually hit. Each page shows the exact PostgreSQL and SQLite message, why it happens, and a broken and fixed query you can run right on the page. Every example is tested on both databases.
Queries
- column "cat" does not exist (double quotes vs single quotes)In SQL, single quotes mean text and double quotes mean a column or table name.
- column "age_months" does not exist (using an alias in WHERE)SQL evaluates WHERE before SELECT, so an alias you create in SELECT doesn't exist yet when WHERE runs.
- relation "pet" does not exist / no such table: petThe database can't find a table with that exact name in the schemas it searches.
- syntax error at or near "FROM" / near "FROM": syntax errorThe parser hit something it didn't expect just before the word in the message.
- more than one row returned by a subquery used as an expressionA subquery used with = must return exactly one value, but yours returns several rows.
- each UNION query must have the same number of columnsEvery SELECT in a UNION must return the same number of columns, in the same order and compatible types.
- column "x" does not exist / no such column: xThe database can't find a column with that name in the tables listed in FROM.
- syntax error at end of input / incomplete inputThe query stops before it's finished: a parenthesis is never closed, a CASE has no END, or a clause ends in mid-air (WHERE, AND).
- unterminated quoted string at or near … / unrecognized tokenA text value opens with ' and never closes, so the rest of the query is read as text.
- invalid UNION/INTERSECT/EXCEPT ORDER BY clause / 1st ORDER BY term does not match any column in the result setAfter UNION, INTERSECT or EXCEPT, ORDER BY sorts the combined result, so it can only name its columns (by name or position), not an expression like LENGTH(name).
- subquery has too many columns / sub-select returns 2 columns - expected 1A subquery used with IN, = or as a value must return exactly one column.
- for SELECT DISTINCT, ORDER BY expressions must appear in select listAfter SELECT DISTINCT category, there's one row per category but several prices behind it, so ORDER BY price has no single value to sort by.
- ORDER BY position 3 is not in select list / 1st ORDER BY term out of rangeA number in ORDER BY means a column position in the select list: ORDER BY 3 needs at least three selected columns.
- wrong number of arguments to function substr() (SQLite)The function was called with too few or too many arguments.
- LIMIT #,# syntax is not supported (PostgreSQL)LIMIT offset, count is MySQL syntax that SQLite also accepts.
- relation "n" does not exist (a recursive CTE without RECURSIVE)A CTE that refers to itself must be declared WITH RECURSIVE.
Joins and grouping
- column "x" must appear in the GROUP BY clause or be used in an aggregate functionEvery column in SELECT must either be listed in GROUP BY or wrapped in an aggregate like MAX() or COUNT().
- column reference "id" is ambiguous / ambiguous column name: idAfter a join, more than one table has a column with that name, so the database doesn't know which one you mean.
- aggregate functions are not allowed in WHEREWHERE filters individual rows before any grouping, so it can't use AVG, SUM or COUNT.
- window functions are not allowed in WHEREWindow functions are computed after WHERE, so you can't filter on them directly.
- missing FROM-clause entry for table "customers"You referenced a table (or alias) that isn't in your FROM or JOIN clauses.
- aggregate function calls cannot be nested / misuse of aggregate function COUNT()You can't put one aggregate inside another, like AVG(COUNT(*)) or SUM(MAX(x)), at the same level of a query.
- window function row_number requires an OVER clause / misuse of window functionROW_NUMBER(), RANK(), LAG() and the other window functions only work with OVER (…), which says how to order (and optionally group) the rows they look at: ROW_NUMBER() OVER (ORDER BY price DESC).
- invalid reference to FROM-clause entry for table "customers"Once a table has an alias in FROM, the query must use the alias: after FROM customers c, write c.name, not customers.name.
- HAVING clause on a non-aggregate query (SQLite)HAVING filters groups, so it needs a grouped query: a GROUP BY or an aggregate in SELECT.
Types and values
- operator does not exist: integer = textYou're comparing (or joining) a number column with a text column.
- invalid input syntax for type integer: "3 years"PostgreSQL tried to turn a piece of text into an integer and the text isn't a valid number.
- division by zeroAt least one row divides by zero.
- function … does not exist / no such functionThe database has no function with that name for those arguments.
- datatype mismatch (SQLite)SQLite is relaxed about types, with two exceptions: an INTEGER PRIMARY KEY column only holds integers, and a table created STRICT checks every column.
- argument of WHERE must be type boolean, not type numericPostgreSQL wants a true-or-false condition after WHERE, AND and OR.
- UNION types text and integer cannot be matchedUNION stacks columns by position, so each position needs the same type on both sides.
- invalid input syntax for type date: "March 1"PostgreSQL couldn't read the text as a date.
- column "age" is of type integer but expression is of type textYou're putting a text value into an integer column.
Changing data
- duplicate key value violates unique constraint "pets_pkey"You're inserting a value that already exists in a column that must be unique (here the primary key id).
- null value in column "name" violates not-null constraintA column declared NOT NULL received no value.
- insert or update violates foreign key constraint "orders_customer_id_fkey"The row points to a parent row that doesn't exist: here an order for customer 12345, but there is no such customer.
- INSERT has more expressions than target columns / table has 4 columns but 5 values were suppliedThe number of values doesn't match the number of columns.
- value too long for type character varying(3)The value has more characters than the column allows.
- there is no unique or exclusion constraint matching the ON CONFLICT specificationON CONFLICT (column) only works on columns covered by a PRIMARY KEY or UNIQUE constraint (or unique index): that's how the database knows what a conflict is.
- relation "pets" already exists / table pets already existsA table (or view, index or sequence, which PostgreSQL calls relations) with that name already exists.
- column "nme" of relation "pets" does not exist / table pets has no column named nmeINSERT or UPDATE names a column the table doesn't have: a typo, a column that was never created, or the wrong table.
PostgreSQL error messages, A–Z
Exactly as PostgreSQL prints them (after ERROR:). Each was produced by the real engine when this page was built.
- aggregate function calls cannot be nested
- aggregate functions are not allowed in WHERE
- argument of AND must be type boolean, not type numeric
- argument of WHERE must be type boolean, not type numeric
- column "age_months" does not exist
- column "age" is of type integer but expression is of type text
- column "cat" does not exist
- column "nme" does not exist
- column "nme" of relation "pets" does not exist
- column "pets.name" must appear in the GROUP BY clause or be used in an aggregate function
- column reference "id" is ambiguous
- date/time field value out of range: "2026-02-30"
- division by zero
- duplicate key value violates unique constraint "pets_pkey"
- each UNION query must have the same number of columns
- for SELECT DISTINCT, ORDER BY expressions must appear in select list
- function datediff(unknown, date) does not exist
- function round(double precision, integer) does not exist
- function round(numeric, integer, integer) does not exist
- function strftime(unknown, date) does not exist
- function substr(text) does not exist
- INSERT has more expressions than target columns
- invalid input syntax for type date: ""
- invalid input syntax for type date: "March 1"
- invalid input syntax for type integer: "3 years"
- invalid input syntax for type integer: "C-99"
- invalid reference to FROM-clause entry for table "customers"
- invalid UNION/INTERSECT/EXCEPT ORDER BY clause
- LIMIT #,# syntax is not supported
- missing FROM-clause entry for table "customers"
- more than one row returned by a subquery used as an expression
- must appear in the GROUP BY clause or be used in an aggregate function
- non-integer constant in ORDER BY
- null value in column "city" of relation "customers" violates not-null constraint
- null value in column "name" of relation "pets" violates not-null constraint
- operator does not exist: integer = text
- ORDER BY position 3 is not in select list
- relation "n" does not exist
- relation "pet" does not exist
- relation "pets" already exists
- subquery has too many columns
- subquery must return only one column
- syntax error at end of input
- syntax error at or near "FROM"
- there is no unique or exclusion constraint matching the ON CONFLICT specification
- UNION types text and integer cannot be matched
- unterminated quoted string at or near "'Austin;"
- value too long for type character varying(3)
- violates foreign key constraint "orders_customer_id_fkey"
- window function lag requires an OVER clause
- window function row_number requires an OVER clause
- window functions are not allowed in WHERE
SQLite error messages, A–Z
Exactly as SQLite prints them. Each was produced by the real engine when this page was built.
- 1st ORDER BY term does not match any column in the result set
- 1st ORDER BY term out of range - should be between 1 and 2
- 3 values for 2 columns
- ambiguous column name: id
- cannot store TEXT value in INTEGER column scores.points
- datatype mismatch
- do not have the same number of result columns
- FOREIGN KEY constraint failed
- HAVING clause on a non-aggregate query
- incomplete input
- misuse of aggregate function AVG()
- misuse of aggregate function COUNT()
- misuse of window function ROW_NUMBER()
- near "FROM": syntax error
- no such column: customers.name
- no such column: nme
- no such function: DATEDIFF
- no such function: now
- no such table: pet
- NOT NULL constraint failed: pets.name
- ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint
- sub-select returns 2 columns - expected 1
- table customers has 4 columns but 2 values were supplied
- table customers has 4 columns but 5 values were supplied
- table pets already exists
- table pets has no column named nme
- UNIQUE constraint failed: pets.id
- unrecognized token: "'Austin;"
- wrong number of arguments to function round()
- wrong number of arguments to function substr()