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
- Skip if it exists, or
DROP TYPE IF EXISTSbefore recreating (mind dependencies). - Use
ALTER TYPEto modify rather than recreate. - Choose a unique type name or a different schema.
Related & next steps
Reference: PostgreSQL 18 — CREATE TYPE.
Thanks — noted. This helps keep the database accurate.