SQL "column does not exist" (tested)
column "x" does not exist means a query referenced a column name PostgreSQL can't find on any table in the query — usually a typo, a column that was renamed or dropped, or code written against a schema that changed since. It happens in any clause that names a column: SELECT, WHERE, INSERT's column list, UPDATE's SET, and ORDER BY, as the five cases below show.
1. Reading the error
PostgreSQL names the exact column it couldn't find and points at it with a caret on the line below:
ERROR: column "sku" does not exist
LINE 1: SELECT sku FROM products;
^
If the name you typed is close to a real column, Postgres adds a HINT guessing what you meant — useful for catching typos fast:
ERROR: column "nam" does not exist
LINE 1: SELECT nam FROM products;
^
HINT: Perhaps you meant to reference the column "products.name".
2. Five reproduced triggers (same underlying cause, five clauses)
| Statement | Exact error |
|---|---|
SELECT sku FROM products; | ERROR: column "sku" does not exist |
SELECT * FROM products WHERE sku = 'abc'; | ERROR: column "sku" does not exist |
INSERT INTO products (name, sku) VALUES ('Gadget', 'g-1'); | ERROR: column "sku" of relation "products" does not exist (note: slightly different wording than SELECT/WHERE) |
UPDATE products SET sku = 'g-1' WHERE id = 1; | ERROR: column "sku" of relation "products" does not exist |
SELECT * FROM products ORDER BY sku; | ERROR: column "sku" does not exist |
INSERT and UPDATE both add of relation "products" to the message, because for those statements Postgres already knows exactly which table the column should belong to. SELECT/WHERE/ORDER BY can involve multiple tables, so the message is more general.
3. The fix depends on why the column is missing
- It's a typo: read the HINT if there is one (section 1). If there isn't, check the real column names with
\d productsin psql, orSELECT column_name FROM information_schema.columns WHERE table_name = 'products';, which is portable SQL (works the same on MySQL and Postgres). - The column genuinely doesn't exist yet (code expects a column a migration hasn't added): add it, tested below.
- The column was renamed or dropped: update the query/code to the new name, or add it back if dropping it was a mistake.
4. Fix: add the column, idempotently
ADD COLUMN IF NOT EXISTS adds the column if missing and does nothing (not an error) if it's already there — safe to run from a migration that might run twice:
psql> ALTER TABLE products ADD COLUMN IF NOT EXISTS sku TEXT;
ALTER TABLE
psql> ALTER TABLE products ADD COLUMN IF NOT EXISTS sku TEXT;
NOTICE: column "sku" of relation "products" already exists, skipping
ALTER TABLE
Both runs succeed. The second prints a NOTICE (not an ERROR) and changes nothing. Without IF NOT EXISTS, the second run would fail with ERROR: column "sku" of relation "products" already exists — the mirror image of this guide's error.
5. Checking programmatically before you query
If your application code needs to check a column exists before using it (for example, supporting two schema versions during a rollout), query information_schema.columns, which is part of the SQL standard and works on PostgreSQL, MySQL and SQL Server alike:
psql> SELECT column_name FROM information_schema.columns
WHERE table_name = 'products' AND column_name = 'sku';
column_name
-------------
sku
(1 row)
Zero rows back means the column isn't there yet; one row means it is.
6. Other databases (per their docs, not measured on this box)
MySQL raises ERROR 1054 (42S22): Unknown column 'sku' in 'field list'. SQL Server raises Invalid column name 'sku'. The cause and the fixes in sections 3-5 are the same; only the wording differs.
Frequently asked questions
Why does the error wording change between SELECT and INSERT?
In our tests, SELECT/WHERE/ORDER BY produced column "sku" does not exist, while INSERT and UPDATE produced column "sku" of relation "products" does not exist. PostgreSQL already knows the single target table for INSERT/UPDATE, so it names it; SELECT can span multiple tables, so it doesn't.
Does PostgreSQL suggest the correct column name?
Sometimes. When the typo is close to a real column, we got HINT: Perhaps you meant to reference the column "products.name". after misspelling "name" as "nam". There's no HINT when the name isn't close to anything real.
How do I add a column without erroring if it's already there?
Use ALTER TABLE ... ADD COLUMN IF NOT EXISTS. We tested running it twice: the first run added the column (ALTER TABLE), the second did nothing but succeeded, printing NOTICE: column already exists, skipping instead of an error.
How can application code check if a column exists before querying it?
Query information_schema.columns, e.g. SELECT column_name FROM information_schema.columns WHERE table_name = 'x' AND column_name = 'y'. We confirmed it returns one row if the column exists and zero if not. It's part of the SQL standard, so the same query works on PostgreSQL, MySQL and SQL Server.
Is this the same error in MySQL and SQL Server?
The cause and fix are the same, but the wording differs. Per their docs (not measured here): MySQL raises 'Unknown column... in field list' with code 1054; SQL Server raises 'Invalid column name'. PostgreSQL, which we tested, says 'column does not exist'.
Written with AI assistance. Measured on 2026-10-03 with PostgreSQL 16.15 (official Docker image), using psql. Every error message below is copy-pasted output, not paraphrased. MySQL and SQL Server enforce the same rule but phrase the error differently (per their docs, not measured here). PlainHeaders is our extension; PostgreSQL and Docker are free.