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));