Skip to content
ERROR: relation 'table_name' does not exist

ERROR: relation 'table_name' does not exist

DodaTech 2 min read

The PostgreSQL error “ERROR: relation ’table_name’ does not exist” means the database could not find a table, view, or other relation with the specified name in the current search path.

What It Means

PostgreSQL uses a schema search path (search_path) to resolve unqualified table names. When you reference table_name without a schema prefix, PostgreSQL checks each schema in search_path in order. If no matching relation is found in any of those schemas, it returns this error.

Why It Happens

  • The table does not exist in any schema accessible by the current user.
  • The table exists in a schema that is not in your search_path, e.g., schema_name.table_name.
  • PostgreSQL column and table names are case-folded to lowercase unless quoted. "TableName" is different from tablename.
  • You connected to the wrong database (e.g., postgres instead of appdb).
  • The table was accidentally dropped or never created by a migration.
  • The user does not have USAGE privilege on the schema containing the table.

How to Fix It

1. List all tables in the current database

psql -d yourdb
\dt

2. List tables across all schemas

\dt *.*

3. Check the current search_path

SHOW search_path;

4. Use a fully qualified name

SELECT * FROM public.table_name;

5. Set the search path to include your schema

SET search_path TO my_schema, public;

6. Verify you are in the correct database

\conninfo

FAQ

What is the default search_path in PostgreSQL?
The default is "$user", public — meaning it first looks for a schema named after the current user, then the public schema. If neither exists or the table is elsewhere, the relation is not found.
How do I grant a user access to a schema?
Run GRANT USAGE ON SCHEMA my_schema TO youruser; and GRANT SELECT ON ALL TABLES IN SCHEMA my_schema TO youruser;. Without USAGE, the user cannot see objects in the schema.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro