Skip to content

/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:

bash
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.mjs

Output

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

sql
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

sql
-- 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