relation does not exist
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.
- 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
A SELECT query references a table that does not exist in the current schema.
SELECT * FROM nonexistent_table;
expected output
ERROR: relation "nonexistent_table" does not exist LINE 1: SELECT * FROM nonexistent_table;
Fix 1
Verify the table name and schema
WHEN 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 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_table
Why 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.
✕ Set search_path = '' (empty) as a security measure without updating queries
All unqualified table references break; every query must be updated with explicit schema prefixes.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev