PostgreSQL Error 42P01: Relation Does Not Exist
Fix PostgreSQL SQLSTATE 42P01 by checking the database, search_path, schema access, relation name, and quoted identifier case.
On this page
PostgreSQL SQLSTATE 42P01 (undefined_table) means the server could not resolve a relation named in the statement. The message is commonly relation "orders" does not exist. A relation can be a table or another table-like object, such as a view. PostgreSQL’s error-code appendix identifies 42P01 as undefined_table and recommends using SQLSTATE codes to identify errors reliably; see the PostgreSQL 18 error code appendix.
Check the database and schema context used by the failing application before creating or renaming objects. The same table name can exist in another database or schema and still be invisible to the current connection.
Check the database and effective schema search path
Run these commands in the same connection or application environment that reports the error:
SELECT current_database(), current_user, current_schema();
SHOW search_path;
SELECT current_schemas(true);
current_database() confirms the connected database. search_path lists schemas PostgreSQL searches for unqualified names. current_schemas(true) shows the effective path after nonexistent schemas and schemas without USAGE permission are ignored. See the PostgreSQL 18 search_path documentation and schema information functions.
If the table belongs to a known schema, test it with a qualified name:
SELECT to_regclass('sales.orders') AS resolved_relation;
to_regclass returns NULL if the name cannot be resolved instead of raising an error. If sales.orders resolves but orders does not, either qualify the object in the application query or set a trusted search_path for the connection. Do not add schemas writable by untrusted users to the search path; PostgreSQL warns that doing so can affect which objects and functions an unqualified name resolves to.
If the intended schema is absent from current_schemas(true), ask the database administrator to check the schema name and the current role’s USAGE privilege. Do not grant schema access without confirming that the role should be allowed to access those objects.
Verify the relation name and capitalization
Unquoted PostgreSQL identifiers are folded to lower case. Double-quoted identifiers preserve their exact case. If a table was created as "Orders", an unquoted orders reference searches for a different name:
-- Created as a quoted, mixed-case name:
CREATE TABLE "Orders" (order_id bigint PRIMARY KEY);
-- Refers to the lower-case name orders:
SELECT * FROM orders;
-- Refers to the actual mixed-case name:
SELECT * FROM "Orders";
Prefer unquoted lower-case identifiers for new objects. If the error message includes a schema-qualified name, compare both parts and the exact capitalization with the migration or table definition. PostgreSQL documents identifier folding and quoting.
You can list visible tables and views in the current database with:
SELECT table_schema, table_name, table_type
FROM information_schema.tables
WHERE table_name IN ('orders', 'Orders')
ORDER BY table_schema, table_name;
The information schema only shows objects accessible to the current user. If the relation is missing from the expected schema, check whether the deployment migration ran against this database and whether the object was renamed or dropped.
Distinguish missing relations from other errors
42P01 means PostgreSQL could not resolve the relation. 42703 (undefined_column) instead means the relation was found but a referenced column was not; see PostgreSQL Error 42703. For unique-key conflicts, see PostgreSQL Error 23505. Browse the PostgreSQL error troubleshooting index for other common errors.