Diagnostic Queries
Symptoms
A query referenced a column that does not exist on any table currently in scope. The name resolved to no column in the FROM list — or it exists on a table you did not actually join.
- The statement aborts with SQLSTATE 42703.
- PostgreSQL often appends a
HINTsuggesting the closest existing column. - Frequently caused by a typo, wrong case, or a forgotten
JOIN.
What the server log shows
ERROR: column "totl" does not exist
LINE 1: SELECT totl FROM orders;
^
HINT: Perhaps you meant to reference the column "orders.total".
STATEMENT: SELECT totl FROM orders;
Why PostgreSQL raises this — what the manual says
Section 4.2.2 Column References:
“correlation is the name of a table (possibly qualified with a schema name), or an alias for a table defined by means of a FROM clause.”
After resolving the tables in FROM, the planner matches each column reference against their columns. A name that matches nothing yields 42703. As with tables, unquoted column names fold to lower case, so a column created as "userId" must be quoted to be found.
Common causes
- A typo in the column name (note the
HINTin the message). - Wrong case on a column that was created with quotes (
"userId"). - The column belongs to a table not included in the
FROM/JOIN. - A renamed or dropped column the query still references.
- Confusing a value with an identifier — string literals need single quotes.
How to fix it
- List the table’s columns:
\d ordersin psql. - Fix the spelling/case, or quote a case-sensitive name exactly:
"userId". - Add the missing table to the
FROM/JOINclause. - If you meant a string value, wrap it in single quotes:
'pending', notpending.
Diagnostic query
-- List the columns of a table
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'orders'
ORDER BY ordinal_position;
Compare the names exactly — watch for case and underscores.
Related & next steps
Reference: PostgreSQL 18 Section 4.2.1 “Column References”.
Thanks — noted. This helps keep the database accurate.