# 42P01: relation does not exist

> Why Postgres says a table doesn't exist when you can see it, and how to fix it on SupaHost. Covers the wrong database, search_path, schema-qualified names and mixed-case names.

Source: https://supahost.app/kb/relation-does-not-exist · Updated 2026-11-11

## What you see

```
ERROR:  42P01: relation "recipes" does not exist
LINE 1: select * from recipes
```

You see this in Studio's SQL editor, in psql, in a migration, or inside a database function or trigger. When a function you call through the Data API (`supabase.rpc()`) hits it, the API returns HTTP 404 with `"code": "42P01"`. When `supabase.from('recipes')` names a table the API doesn't know, you get `PGRST205` ("Could not find the table ... in the schema cache") instead. That case is covered in [PostgREST not seeing new tables](/kb/postgrest-schema-cache).

## Why it happens

Postgres looks up an unqualified name like `recipes` in the schemas on the current `search_path`, inside the database you're connected to. The error means none of them has a table by that exact name. The usual causes:

- **You're in the wrong database.** Each SupaHost project is its own database on the instance's Postgres server.
- **The schema isn't on the search path.** This is common in functions declared with `set search_path = ''`, and in triggers on `auth.users`, which run as `supabase_auth_admin` and don't search `public`.
- **The name has capitals.** A table created as `"Recipes"` must be quoted forever. Unquoted names are folded to lower case.
- **The table was never created.** The migration that makes it failed or rolled back, or it ran on a different project or branch.

## How to fix it

1. Check where your session is:

   ```sql
   select current_database(), current_user, current_setting('search_path');
   ```

2. Find the table, whatever its schema or case:

   ```sql
   select n.nspname as schema, c.relname as name, c.relkind as kind
   from pg_class c
   join pg_namespace n on n.oid = c.relnamespace
   where c.relname ilike '%recipe%';
   ```

3. If it's in another schema, qualify the name: `select * from public.recipes;`. In functions with an empty search path, qualify every table, view and function:

   ```sql
   create or replace function public.recipe_count(p_author uuid)
   returns bigint
   language sql
   stable
   set search_path = ''
   as $$
     select count(*) from public.recipes where author_id = p_author;
   $$;
   ```

4. If the name has capitals, quote it (`select * from "Recipes";`) or rename it to snake_case. See [camelCase table or column names not working](/kb/camelcase-identifiers).

5. If the table really is missing, re-run the migration that creates it and check the result for errors.

## On SupaHost

- Project databases are named `p_` plus the project name with hyphens turned into underscores. Project `app-one` lives in `p_app_one`. If your tunnel connection string ends in `/postgres`, you're in the instance's own `postgres` database, which holds none of your tables. Copy the string from *Dashboard → your project → **Connect** tab → Database → Show connection string*.
- Studio is opened per project, so the SQL editor always points at that project's database. Check the project name in the URL if you have several open.
- The MCP `get_advisors` tool flags functions with a mutable search path (`function_search_path_mutable`). The fix is `set search_path = ''`, but after that every name inside the function must be schema-qualified, or you get this error.
- A sign-up trigger that inserts into `profiles` without `public.` fails like this. Supabase Auth then reports [Database error saving new user](/kb/database-error-saving-new-user).

## Related

- [Connecting to your database](/docs/database/connecting)
- [Database functions](/docs/database/functions)
- [PostgREST not seeing new tables, columns or functions](/kb/postgrest-schema-cache)
- [camelCase table or column names not working](/kb/camelcase-identifiers)
