/errors/postgresql/relation-does-not-exist
PostgreSQL: ERROR: relation "users" does not exist
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
- tool
- PostgreSQL
- exit code
- 0
- versions
- PostgreSQL 12 – 18
- os
- any
PostgreSQL raises ERROR: relation "users" does not exist (SQLSTATE 42P01) when it cannot find a table, view or sequence with that name. "Relation" is PostgreSQL's word for any table-like object. The name is looked up in the schemas on the search_path, after folding unquoted names to lowercase.
Reproduce it
PostgreSQL 18 running in-process with PGlite (the real PostgreSQL server compiled to WebAssembly), printing the error fields like psql does:
npm init -y >/dev/null
npm install --silent --no-audit --no-fund @electric-sql/pglite@0.5.10 >/dev/null 2>&1
cat > q.mjs <<'EOF'
import { PGlite } from "@electric-sql/pglite";
const db = new PGlite();
const run = async (sql) => {
try { await db.query(sql); console.log("OK ", sql); }
catch (e) { console.log(`ERROR: ${e.message} (SQLSTATE ${e.code}) <- ${sql}`); }
};
await run(`select * from users`);
await run(`create schema app`);
await run(`create table app.users (id int)`);
await run(`select * from users`);
await run(`select * from app.users`);
await run(`create table "Orders" (id int)`);
await run(`select * from Orders`);
await run(`select * from "Orders"`);
EOF
node q.mjsOutput
ERROR: relation "users" does not exist (SQLSTATE 42P01) <- select * from users OK create schema app OK create table app.users (id int) ERROR: relation "users" does not exist (SQLSTATE 42P01) <- select * from users OK select * from app.users OK create table "Orders" (id int) ERROR: relation "orders" does not exist (SQLSTATE 42P01) <- select * from Orders OK select * from "Orders"
Find the table
SELECT current_database(), current_schema();
SHOW search_path;
SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_name ILIKE 'users';In psql, \dt *.* lists tables in every schema.
Fixes
-- qualify the schema
SELECT * FROM app.users;
-- or put the schema on the search path (session, or permanently for a role)
SET search_path TO app, public;
ALTER ROLE app_user SET search_path TO app, public;
-- mixed-case names must be quoted every time; renaming to lowercase avoids that
ALTER TABLE "Orders" RENAME TO orders;Sources
Related pages
codes · postgresqlPostgreSQL SQLSTATE error codes: 23505, 23503, 42P01, 40001 and moreThe PostgreSQL SQLSTATE codes apps handle most: 23505 unique violation, 23503 foreign key, 23502 not null, 42P01 missing table, 40001 serialization failure.errors · postgresqlPostgreSQL: duplicate key value violates unique constraintPostgreSQL raises duplicate key value violates unique constraint (SQLSTATE 23505) when a key repeats. Read the DETAIL line, then upsert or reset the sequence.cheat sheets · postgresqlpsql cheat sheet: connect, list, describe and run SQL filespsql cheat sheet: connection strings, \l \dt \d+ and \du, switching database, expanded output, timing, running files with -f, \copy to CSV, and catalog queries.