When using ALTER TYPE ... ADD VALUE in PostgreSQL, omitting the BEFORE or AFTER keywords appends the new value to the end of the enum type. This can break queries that rely on enum ordering (e.g., using the < or > operators), as new values will be considered 'greater than' all existing values regardless of their logical meaning.
To ensure a new value is placed correctly within the existing sequence, explicitly specify its position using BEFORE 'existing_value' or AFTER 'existing_value'.
-- Existing type
CREATE TYPE status AS ENUM ('draft', 'submitted', 'approved', 'rejected');
-- Query relying on order
SELECT * FROM papers WHERE status < 'approved';
-- INCORRECT: Appends to the end, making 'pending_review' > 'approved'
ALTER TYPE status ADD VALUE 'pending_review';
-- CORRECT: Inserts value in the specific logical position
ALTER TYPE status ADD VALUE 'pending_review' BEFORE 'approved';
-- OR
ALTER TYPE status ADD VALUE 'pending_review' AFTER 'submitted';