PostgreSQL 17.12Lab-verified · 2026-11-30

PostgreSQL 42704: type "citext" does not exist (undefined_object)

The statement names a type, role, constraint or similar object that PostgreSQL cannot find.

PostgreSQL 17.12
42704: type "citext" does not exist

Jump to a cause

  1. 01Using citext (or another extension type) before CREATE EXTENSION
  2. 02GRANT to a role that does not exist on this server
  3. 03DROP CONSTRAINT with a guessed name
  4. 04An enum type created in another schema that is not on search_path

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.

Reproducerun as lab_a
CREATE TABLE members (id int PRIMARY KEY, email citext UNIQUE);
✕ ERROR
ERROR:  42704: type "citext" does not exist
LINE 1: CREATE TABLE members (id int PRIMARY KEY, email citext UNIQU...
                                                        ^
Fixrun as postgres
CREATE EXTENSION IF NOT EXISTS citext;
OUTPUT
CREATE EXTENSION

Run 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.

After the fixrun as lab_a
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';
✓ SUCCESS
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
Setuprun as postgres
DROP ROLE IF EXISTS report_reader;
OUTPUT
NOTICE:  00000: role "report_reader" does not exist, skipping
DROP ROLE
Setuprun as lab_a
CREATE TABLE sales (id int PRIMARY KEY, amount numeric);
OUTPUT
CREATE TABLE
Reproducerun as lab_a
GRANT SELECT ON sales TO report_reader;
✕ ERROR
ERROR:  42704: role "report_reader" does not exist
Checkrun as postgres
SELECT rolname FROM pg_roles WHERE rolname LIKE 'report%';
OUTPUT
 rolname
---------
(0 rows)
Fixrun as postgres
CREATE ROLE report_reader;
OUTPUT
CREATE ROLE

pg_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.

After the fixrun as lab_a
GRANT SELECT ON sales TO report_reader;
✓ SUCCESS
GRANT

03DROP 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
Setuprun as lab_a
CREATE TABLE customers (id int PRIMARY KEY, email text UNIQUE);
OUTPUT
CREATE TABLE
Reproducerun as lab_a
ALTER TABLE customers DROP CONSTRAINT uk_customers_email;
✕ ERROR
ERROR:  42704: constraint "uk_customers_email" of relation "customers" does not exist
Checkrun as lab_a
SELECT conname, contype FROM pg_constraint WHERE conrelid = 'customers'::regclass ORDER BY conname;
OUTPUT
       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.

After the fixrun as lab_a
ALTER TABLE customers DROP CONSTRAINT customers_email_key;
✓ SUCCESS
ALTER TABLE

04An 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
Setuprun as postgres
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;
OUTPUT
NOTICE:  00000: drop cascades to type app.order_status
DROP SCHEMA
CREATE SCHEMA
CREATE TYPE
GRANT
Reproducerun as lab_a
CREATE TABLE orders (id int PRIMARY KEY, status order_status);
✕ ERROR
ERROR:  42704: type "order_status" does not exist
LINE 1: CREATE TABLE orders (id int PRIMARY KEY, status order_status...
                                                        ^
Checkrun as lab_a
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;
OUTPUT
 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'.

After the fixrun as lab_a
CREATE TABLE orders (id int PRIMARY KEY, status app.order_status);
INSERT INTO orders VALUES (1, 'paid');
SELECT * FROM orders;
✓ SUCCESS
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