pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: amaury@castordoc.com
Subject: BUG #17271: Updating enum columns type fails when constraints exist
Date: Thu, 04 Nov 2021 13:42:00 +0000
Message-ID: <17271-8b4317357c4991e2@postgresql.org> (raw)

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



view thread (6+ messages)  latest in thread

Message-ID: <17271-8b4317357c4991e2@postgresql.org>
Permalink:  ../17271-8b4317357c4991e2@postgresql.org/
Also on:    postgresql.org/message-id/17271-8b4317357c4991e2@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, amaury@castordoc.com
  Subject: Re: BUG #17271: Updating enum columns type fails when constraints exist
  In-Reply-To: <17271-8b4317357c4991e2@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox