Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-30 · container image postgres:17
SQLSTATE 42704 is undefined_object. Missing tables give 42P01 and missing columns 42703, but a missing type, role or constraint gives 42704 with "... does not exist".
The object is usually not truly gone: an extension was never installed, a role was never created on this server, the constraint has an auto-generated name, or the type lives in a schema outside your search_path. Here are 4 cases reproduced on PostgreSQL 17.
01Using citext (or another extension type) before CREATE EXTENSION
citext is not a built-in type. It comes from the citext extension, which has to be installed once per database. Without it, CREATE TABLE fails with type "citext" does not exist.
CREATE TABLE members (id int PRIMARY KEY, email citext UNIQUE);ERROR: 42704: type "citext" does not exist
LINE 1: CREATE TABLE members (id int PRIMARY KEY, email citext UNIQU...
^CREATE EXTENSION IF NOT EXISTS citext;CREATE EXTENSIONRun CREATE EXTENSION IF NOT EXISTS citext; in that database (here as postgres). After that the table is created, and WHERE email = 'kim@example.com' finds the row stored as Kim@Example.com, because citext compares case-insensitively.
CREATE TABLE members (id int PRIMARY KEY, email citext UNIQUE);
INSERT INTO members VALUES (1, 'Kim@Example.com');
SELECT id, email FROM members WHERE email = 'kim@example.com';CREATE TABLE
INSERT 0 1
id | email
----+-----------------
1 | Kim@Example.com
(1 row)02GRANT to a role that does not exist on this server
Roles are per server (cluster), not per database. A GRANT script copied from another server fails when the role was never created here.
Setup
DROP ROLE IF EXISTS report_reader;NOTICE: 00000: role "report_reader" does not exist, skipping
DROP ROLECREATE TABLE sales (id int PRIMARY KEY, amount numeric);CREATE TABLEGRANT SELECT ON sales TO report_reader;ERROR: 42704: role "report_reader" does not existSELECT rolname FROM pg_roles WHERE rolname LIKE 'report%'; rolname
---------
(0 rows)CREATE ROLE report_reader;CREATE ROLEpg_roles returns 0 rows for report_reader. Create the role first with CREATE ROLE report_reader; (as a superuser or a role with CREATEROLE); then the same GRANT succeeds.
GRANT SELECT ON sales TO report_reader;GRANT03DROP CONSTRAINT with a guessed name
The UNIQUE constraint was declared inline (email text UNIQUE), so PostgreSQL named it automatically. The name uk_customers_email does not exist.
Setup
CREATE TABLE customers (id int PRIMARY KEY, email text UNIQUE);CREATE TABLEALTER TABLE customers DROP CONSTRAINT uk_customers_email;ERROR: 42704: constraint "uk_customers_email" of relation "customers" does not existSELECT conname, contype FROM pg_constraint WHERE conrelid = 'customers'::regclass ORDER BY conname; conname | contype
---------------------+---------
customers_email_key | u
customers_pkey | p
(2 rows)pg_constraint shows the real names: customers_email_key (u = unique) and customers_pkey. Auto-generated names follow <table>_<column>_key for UNIQUE and <table>_pkey for the primary key. Dropping customers_email_key works.
ALTER TABLE customers DROP CONSTRAINT customers_email_key;ALTER TABLE04An enum type created in another schema that is not on search_path
order_status exists, but in schema app. The default search_path is "$user", public, so an unqualified order_status is not found.
Setup
DROP SCHEMA IF EXISTS app CASCADE;
CREATE SCHEMA app;
CREATE TYPE app.order_status AS ENUM ('new', 'paid', 'shipped');
GRANT USAGE ON SCHEMA app TO lab_a;NOTICE: 00000: drop cascades to type app.order_status
DROP SCHEMA
CREATE SCHEMA
CREATE TYPE
GRANTCREATE TABLE orders (id int PRIMARY KEY, status order_status);ERROR: 42704: type "order_status" does not exist
LINE 1: CREATE TABLE orders (id int PRIMARY KEY, status order_status...
^SELECT n.nspname AS schema, t.typname FROM pg_type t JOIN pg_namespace n ON n.oid = t.typnamespace WHERE t.typname = 'order_status';
SHOW search_path; schema | typname
--------+--------------
app | order_status
(1 row)
search_path
-----------------
"$user", public
(1 row)The catalog query shows the type in schema app, and SHOW search_path shows app is not in it. Qualify the type as app.order_status (the user needs USAGE on schema app, granted in setup). The table is created and accepts 'paid'.
CREATE TABLE orders (id int PRIMARY KEY, status app.order_status);
INSERT INTO orders VALUES (1, 'paid');
SELECT * FROM orders;CREATE TABLE
INSERT 0 1
id | status
----+--------
1 | paid
(1 row)FAQ
What does PostgreSQL error 42704 mean?
undefined_object: a type, role, constraint, index or similar object in the statement does not exist (or is not visible on your search_path).
How do I fix type "citext" does not exist?
Install the extension in that database: CREATE EXTENSION IF NOT EXISTS citext;. Extensions are per database, so a new database needs it again.
How do I find the real name of a constraint to drop?
Query pg_constraint: SELECT conname, contype FROM pg_constraint WHERE conrelid = 'customers'::regclass;.
Why does role "xxx" does not exist appear when the role exists on another server?
Roles are not copied with a dump of a single database. Create the role on the target server before running GRANT.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12