Diagnostic Queries
Symptoms
A query referenced a table/alias in a column reference that is not listed in the FROM clause. PostgreSQL raises SQLSTATE 42P01 (undefined_table).
- A qualified column refers to a table not in FROM.
- Common after renaming via an alias but using the original name.
- Often a forgotten JOIN.
What the server log shows
ERROR: missing FROM-clause entry for table "o"
LINE 1: SELECT o.id FROM orders ord;
Why PostgreSQL raises this — what the manual says
As Section 7.2.1 The FROM Clause explains:
Every table or alias used in a column qualification must appear in the query’s FROM clause; referencing a table name that is not listed there (or using the original name after assigning it an alias) leaves the reference unresolved.
Every table referenced in column qualifications must appear in the FROM clause (by name or alias). Referencing a name that isn’t there — e.g. using the real name after assigning an alias, or forgetting a JOIN — makes the reference unresolved, so PostgreSQL reports 42P01.
Common causes
- Using the table’s original name after assigning it an alias.
- Forgetting to add the table to FROM or a JOIN.
- A typo in the table/alias qualifier.
How to fix it
- Reference the alias you defined (or remove the alias).
- Add the missing table to the FROM/JOIN clause.
- Correct the qualifier to match a table in scope.
Related & next steps
Reference: PostgreSQL 18 Section 7.2 “Table Expressions”.
Thanks — noted. This helps keep the database accurate.