42P01ERRORTier 1 — Safe✅ HIGH confidencerelation does not exist
What this means
The query parser could not find a table, view, materialized view, sequence, or index with the given name in the current search_path. The lookup happens at parse time before any execution, so the statement is rejected immediately.
Why it happens
- 1Misspelled table name in the query
- 2Table exists in a different schema that is not in the current search_path
- 3Table was created in a different database
- 4Table has not been created yet (migration not run, CREATE TABLE omitted)
- 5Table name was quoted when created (making it case-sensitive) but referenced unquoted
How to reproduce
A SELECT query references a table that does not exist in the current schema.
SELECT * FROM nonexistent_table;Fix 1: Verify the table name and schema
When unsure which schema the table lives in.
SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_name ILIKE 'nonexistent_table';
-- Then query with explicit schema prefix
SELECT * FROM myschema.my_table;Why this works
Postgres resolves unqualified names by searching schemas in the order listed in search_path (default: "$user", public). Querying information_schema.tables reveals the actual schema; qualifying the name bypasses search_path resolution entirely.
Fix 2: Set search_path to include the target schema
When the table is in a non-public schema and you want unqualified name resolution to work.
SET search_path TO myschema, public;
SELECT * FROM my_table; -- now resolves to myschema.my_tableWhy this works
The parser resolves each unqualified relation name by iterating search_path schemas in order and calling RangeVarGetRelid() for each. Adding the target schema to the front of search_path makes the lookup succeed.
What not to do
Set search_path = '' (empty) as a security measure without updating queries
Why it's wrong: All unqualified table references break; every query must be updated with explicit schema prefixes.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
📚 Feature docs: https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH
🔧 Source ref: src/backend/catalog/namespace.c — RangeVarGetRelid()
📖 Further reading: Schema Search Path
Confidence assessment
✅ HIGH confidence
Highly stable error. The name resolution mechanism and search_path behaviour have been consistent across all modern Postgres versions. Edge case: pg_catalog is always implicitly searched first regardless of search_path setting.
See also
📄 Reference pages