PostgreSQL Error 42P01: Undefined Table / Relation Does Not Exist
ERROR: relation "users_list" does not exist
LINE 1: SELECT * FROM users_list;
^What is PostgreSQL Error 42P01?
PostgreSQL SQLSTATE 42P01 occurs when a query attempts to reference a table, view, or sequence that does not exist in the active schema search path. PostgreSQL labels database tables and views as 'relations' in its parser errors.
Common Causes
- 1
Typo in the table name
- 2
Table is in a non-public schema (e.g., 'auth' or 'api') and schema prefix is missing
- 3
Case sensitivity issues — tables created with quoted capital letters must be queried with quotes
- 4
Database migrations have not been run on the target connection environment
- 5
Search path does not include the custom schema where the table resides
Step-by-Step Solutions
Verify table existence in the active database: \dt or query pg_tables
Qualify schema names: SELECT * FROM schema_name.table_name;
Check casing: if created as "Users", query as SELECT * FROM "Users";
Inspect and update search_path configuration: SET search_path TO schema_name, public;
Ensure migration scripts ran successfully and check the active database context
Prevention Tips
Adopt a strict lowercase snake_case standard for all table and schema names
Verify your database connection URL points to the exact target database and schema
Configure the default search_path inside postgresql.conf or alter role configurations
Frequently Asked Questions
What does 'relation' mean in PostgreSQL errors?
How do I check and modify search_path in PostgreSQL?
Related Errors
Still Stuck?
Ask our AI SQL Assistant or the community — get answers in seconds.