42P01
PostgreSQLERRORCommonUndefined TableHIGH confidence

relation 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
  1. 1Misspelled table name in the query
  2. 2Table exists in a different schema that is not in the current search_path
  3. 3Table was created in a different database
  4. 4Table has not been created yet (migration not run, CREATE TABLE omitted)
  5. 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.

trigger — this will error
trigger — this will error
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.

Verify the table name and schema
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 include the target schema
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.

What not to do

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.

Sources
Official documentation ↗

src/backend/catalog/namespace.c — RangeVarGetRelid()

Schema Search Path

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors