BUG #17271: Updating enum columns type fails when constraints exist - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #17271: Updating enum columns type fails when constraints exist
Date
Msg-id 17271-8b4317357c4991e2@postgresql.org
Whole thread Raw
Responses Re: BUG #17271: Updating enum columns type fails when constraints exist
Re: BUG #17271: Updating enum columns type fails when constraints exist
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      17271
Logged by:          Amaury Dumoulin
Email address:      amaury@castordoc.com
PostgreSQL version: 12.8
Operating system:   alpine 3.14 on docker (host macOs 11.6)
Description:

Error message upon failure

The following fails

CREATE TYPE direction_state AS ENUM('UP', 'DOWN');
CREATE TABLE example (id SERIAL PRIMARY KEY, direction direction_state NOT
NULL, below BOOLEAN NOT NULL);
ALTER TABLE example ADD CONSTRAINT ck_example_direction CHECK ((direction =
'DOWN' AND below) OR (NOT below));
ALTER TYPE direction_state RENAME TO direction_state_old;
CREATE TYPE direction_state AS ENUM('UP', 'DOWN', 'UNKNOWN');
ALTER TABLE example ALTER COLUMN direction TYPE direction_state USING
direction::text::direction_state;
DROP TYPE direction_state_old

With a sibyllin error message
ERROR:  operator does not exist: direction_state = direction_state_old
HINT:  No operator matches the given name and argument types. You might need
to add explicit type casts.

If we drop and recreate the constraint it works

CREATE TYPE direction_state AS ENUM('UP', 'DOWN');
CREATE TABLE example (id SERIAL PRIMARY KEY, direction direction_state NOT
NULL, below BOOLEAN NOT NULL);
ALTER TABLE example ADD CONSTRAINT ck_example_direction CHECK ((direction =
'DOWN' AND below) OR (NOT below));
ALTER TYPE direction_state RENAME TO direction_state_old;
CREATE TYPE direction_state AS ENUM('UP', 'DOWN', 'UNKNOWN');
ALTER TABLE example DROP CONSTRAINT ck_example_direction;
ALTER TABLE example ALTER COLUMN direction TYPE direction_state USING
direction::text::direction_state;
DROP TYPE direction_state_old
ALTER TABLE example ADD CONSTRAINT ck_example_direction CHECK ((direction =
'DOWN' AND below) OR (NOT below));


pgsql-bugs by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: ERROR: posting list tuple with 20 items cannot be split at offset 168
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #17271: Updating enum columns type fails when constraints exist