unsafe use of new enum value
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.
- 1Using a new enum label in the same transaction that added it with ALTER TYPE ... ADD VALUE
Using a new enum value in the same transaction that added it.
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.
-- 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.
ALTER TYPE ... ADD VALUE introduced in Postgres 9.1. The same-transaction restriction has applied since then.
Class 55 — Object Not in Prerequisite State (Postgres-specific)
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev