SQLSTATE 42704 ERROR Class 42: Syntax Error or Access Rule Violation

undefined_object type “…” does not exist — 42704

PostgreSQL error "type "…" does not exist" (SQLSTATE 42704): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A statement referenced a data type, domain, enum, or composite type that does not exist in any schema on the search_path. PostgreSQL raises SQLSTATE 42704 (undefined_object) while parsing the type name.

  • Common in CREATE TABLE, CAST(… AS …), or function signatures.
  • The caret points at the unknown type name.
  • Frequently caused by a missing extension or a type defined in another schema.

What the server log shows

ERROR:  type "citext" does not exist
LINE 1: CREATE TABLE t (email citext);
                              ^

Why PostgreSQL raises this — what the manual says

As the CREATE TYPE reference (Description) explains:

A statement referenced a data type, domain, or enum that is not defined in the current search path; the type must be created (or schema-qualified) before it can be used in a column definition or cast.

Type names resolve through pg_type using the same search_path rules as relations. If the type lives in an unlisted schema, was never created, or is supplied by an extension that is not installed, resolution fails with 42704.

Common causes

  • An extension type (citext, hstore, uuid helpers, vector) whose extension is not installed.
  • A custom type/enum/domain created in a schema not on the search_path.
  • A typo or wrong case in the type name.
  • Restoring a dump before its extensions/types were created.

How to fix it

  1. Install the extension that provides the type: CREATE EXTENSION IF NOT EXISTS citext;.
  2. Schema-qualify the type (app.status_enum) or add its schema to search_path.
  3. Create the missing type/enum/domain before the object that uses it.
  4. Check spelling and case against \dT in psql.

Diagnostic query

-- Find every schema that defines a type by this name
SELECT n.nspname AS schema, t.typname, t.typtype
FROM pg_type t JOIN pg_namespace n ON n.oid = t.typnamespace
WHERE t.typname = 'citext';

typtype: b=base, c=composite, d=domain, e=enum, r=range.

Related & next steps

Reference: PostgreSQL 18 — CREATE TYPE.

Was this helpful?