42703
PostgreSQLERRORCommonUndefined ColumnHIGH confidence

column does not exist

What this means

The query parser found the referenced table but could not locate a column with the given name in that table's attribute list. Like 42P01, this is a parse-time error caught before any data is touched.

Why it happens
  1. 1Misspelled column name in SELECT, WHERE, ORDER BY, or JOIN condition
  2. 2Column was renamed with ALTER TABLE RENAME COLUMN but queries were not updated
  3. 3Column exists in a different table that is not in scope for the query
  4. 4Column name was double-quoted during creation (case-sensitive) but referenced in lowercase
  5. 5Referencing a column alias defined in SELECT from within a WHERE clause (not yet in scope)
How to reproduce

A SELECT query references a column name that does not exist on the table.

trigger — this will error
trigger — this will error
CREATE TABLE products (
  id    SERIAL PRIMARY KEY,
  title TEXT NOT NULL
);

SELECT product_name FROM products; -- "title" exists, not "product_name"

expected output

ERROR:  column "product_name" does not exist
LINE 1: SELECT product_name FROM products;

Fix

Inspect table columns and correct the name

WHEN When the column exists under a different name or casing.

Inspect table columns and correct the name
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'products'
ORDER BY ordinal_position;

-- Use the correct column name
SELECT title FROM products;

Why this works

The parser resolves column references by scanning the RTE (range table entry) attribute list built from pg_attribute. information_schema.columns is a view over pg_attribute and shows the canonical stored names including their case as created.

What not to do

Use SELECT * to avoid specifying column names

Masks the schema and makes queries fragile to future column additions or removals; does not fix the underlying naming issue.

Sources
Official documentation ↗

src/backend/parser/parse_relation.c — scanRTEForColumn()

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors