scribase
SQLSTATE 42P01undefined_tableHTTP 404

Postgres error 42P01: undefined table

relation "x" does not exist

The table or view name could not be found on the current search_path.

Common causes

  • The table is in another schema and the name is not schema-qualified.
  • Mixed-case names: a table created as "Users" (quoted) must always be referenced with quotes; unquoted users is a different name.
  • The migration that creates it has not run on this database or branch.

How to fix it

  • Qualify the name (public.users) or check show search_path;
  • Use lower-case unquoted names for new tables.
  • List tables with \dt *.* or select from information_schema.tables to see where it lives.

Through a REST API

PostgREST, the REST layer behind supabase-js and Scribase, answers HTTP 404 for this error and returns the SQLSTATE in the code field of the JSON error body. PostgREST answers 404. It also has to reload its schema cache after a migration; a table created a moment ago may not be visible until the reload finishes.

Questions

What does Postgres error 42P01 mean?

42P01 is undefined_table in class 42 (Syntax Error or Access Rule Violation). The table or view name could not be found on the current search_path.

How do I fix 42P01?

Qualify the name (public.users) or check show search_path; Use lower-case unquoted names for new tables. List tables with \dt *.* or select from information_schema.tables to see where it lives.

What HTTP status does a REST API return for 42P01?

PostgREST, the REST layer behind supabase-js, answers 404.

Other class 42 errors

  • 42501 permission denied for table x / new row violates row-level security policy for table "x"
  • 42601 syntax error at or near "x"
  • 42P07 relation "x" already exists
  • 42P05 prepared statement "s0" already exists
  • 42703 column "x" does not exist
  • 42702 column reference "x" is ambiguous