In a PostgreSQL migration I would like to change the type of a column to a different enum.
But when I try
CREATE TYPE job_status_new AS ENUM (
'todo',
'doing',
'succeeded',
'failed',
'cancelled',
'aborted'
);
ALTER TABLE jobs
ALTER COLUMN status TYPE job_status_new
USING (CASE
WHEN status::text = 'aborting' THEN 'aborted'::job_status_new
ELSE status::text::job_status_new
END);
I end up with the error
ERROR: operator does not exist: job_status_new = job_status at character xxx
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
I don’t know how I can be even more explicit.
I even tried
ALTER TABLE jobs
ALTER COLUMN status TYPE job_status_new
USING (CASE
WHEN status::text = 'aborting' THEN 'aborted'::job_status_new
ELSE 'todo'::job_status_new
END);
to make sure that every status exists in the new enum, but that also doesn’t work.
How can I change that type?