Symptoms
The table or view does not exist, or is not visible on the search_path.
- The error is written to the server log and returned to the client carrying
SQLSTATE 42P01. - Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
- PL/pgSQL can trap it by name:
EXCEPTION WHEN undefined_table THEN.
Environment
Severity: ERROR | PostgreSQL versions: 12, 13, 14, 15, 16, 17
Reproduce with the exact statement and read the full message in the server log (raise log_min_messages / set log_min_error_statement for more context).
Root Cause
relation does not exist — the name is wrong, lives in another schema, or has not been created in this database.
Common causes:
- Wrong schema or
search_path. - Case mismatch on the relation name.
- Migrations not yet run in this database.
- Querying another session's temporary table.
Diagnostic Queries
Recovery
Steps to resolve 42P01:
- Confirm it exists and where:
SELECT schemaname, tablename FROM pg_tables WHERE tablename = '...';. - Schema-qualify the name or fix
search_path. - Match case and quoting exactly.
- Ensure migrations ran against this database.
Reference: PostgreSQL error codes — Class 42 (Syntax Error or Access Rule Violation).
Thanks — noted. This helps keep the database accurate.