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

duplicate_object type “…” already exists — 42710

PostgreSQL error "type "…" already exists" (SQLSTATE 42710): 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 CREATE TYPE (or a command that implicitly creates a type) tried to define a type whose name already exists in the schema. PostgreSQL raises SQLSTATE 42710 (duplicate_object).

  • A type with that name already exists in the schema.
  • Note: creating a table also creates a composite type of the same name.
  • Common in re-run migration scripts.

What the server log shows

ERROR:  type "status_enum" already exists

Why PostgreSQL raises this — what the manual says

the CREATE TYPE reference (Array Types):

“Whenever a user-defined type is created, PostgreSQL automatically creates an associated array type, whose name consists of the element type’s name prepended with an underscore, and truncated if necessary to keep it less than NAMEDATALEN bytes long.”

Type names are unique within a schema (and tables implicitly create a same-named composite type). Defining a duplicate collides with the existing type, so PostgreSQL reports 42710.

Common causes

  • Re-running a migration that creates the type.
  • A name clash with a table’s implicit composite type.
  • Two definitions of the same type name in one schema.

How to fix it

  1. Skip if it exists, or DROP TYPE IF EXISTS before recreating (mind dependencies).
  2. Use ALTER TYPE to modify rather than recreate.
  3. Choose a unique type name or a different schema.

Related & next steps

Reference: PostgreSQL 18 — CREATE TYPE.

Was this helpful?