55P04
PostgreSQLERRORNotableObject Not in Prerequisite StateHIGH confidence

unsafe use of new enum value

What this means

SQLSTATE 55P04 is raised when a newly added enum value (via ALTER TYPE ... ADD VALUE) is used in a query within the same transaction that added it. Postgres cannot safely use a new enum value until the transaction that added it commits.

Why it happens
  1. 1Using a new enum label in the same transaction that added it with ALTER TYPE ... ADD VALUE
How to reproduce

Using a new enum value in the same transaction that added it.

trigger — this will error
trigger — this will error
BEGIN;
ALTER TYPE status_enum ADD VALUE 'archived';
INSERT INTO orders (status) VALUES ('archived'); -- 55P04: value not committed yet
COMMIT;

expected output

ERROR:  unsafe use of new value "archived" of enum type status_enum
HINT:  New enum values must be committed before they can be used.

Fix

Commit the ALTER TYPE in a separate transaction before using the new value

WHEN When adding a new enum value and then using it.

Commit the ALTER TYPE in a separate transaction before using the new value
-- Transaction 1:
ALTER TYPE status_enum ADD VALUE 'archived';
-- COMMIT;

-- Transaction 2 (after COMMIT):
INSERT INTO orders (status) VALUES ('archived');

Why this works

The new enum value is not visible to catalog lookups until the adding transaction commits. Using it in two separate transactions resolves the ordering dependency.

Version notes
Postgres 9.1+

ALTER TYPE ... ADD VALUE introduced in Postgres 9.1. The same-transaction restriction has applied since then.

Sources
Official documentation ↗

Class 55 — Object Not in Prerequisite State (Postgres-specific)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors