column does not exist
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.
- 1Misspelled column name in SELECT, WHERE, ORDER BY, or JOIN condition
- 2Column was renamed with ALTER TABLE RENAME COLUMN but queries were not updated
- 3Column exists in a different table that is not in scope for the query
- 4Column name was double-quoted during creation (case-sensitive) but referenced in lowercase
- 5Referencing a column alias defined in SELECT from within a WHERE clause (not yet in scope)
A SELECT query references a column name that does not exist on the table.
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.
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.
✕ 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.
src/backend/parser/parse_relation.c — scanRTEForColumn()
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev