Allow deleting enum value

From: Maksim Kita <kitaetoya(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Allow deleting enum value
Date: 2020-10-07 14:26:56
Message-ID: 20201007142656.GA181015@yetti
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

There is a question related to TODO task with name "Allow deleting enumerated values from an existing enumerated data type".
I made simple changes in parser and implement RemoveEnumLabel function, but as I understand if enum value that we want to
delete is in use by some tables, we have to prevent deletion to avoid inconsistency.

Could you please provide some references where similar functionality was implemented ? Thanks.

Attached basic patch without handling dependencies.

Example of problem that I mention using basic implementation:

postgres=# CREATE TYPE enum_test as ENUM ('1', '2', '3');
CREATE TYPE
postgres=# CREATE TYPE test_enum as ENUM ('1', '2', '3');
CREATE TYPE
postgres=# CREATE TABLE test_table (value test_enum);
CREATE TABLE
postgres=# INSERT INTO test_table VALUES ('1'), ('2');
INSERT 0 2
postgres=# ALTER TYPE test_enum DELETE VALUE '2';
ALTER TYPE
postgres=# SELECT enum_range(NULL::test_enum);
enum_range
------------
{1,3}
(1 row)

postgres=# SELECT * FROM test_table;
ERROR: invalid internal value for enum: 16396

Best regards,
Maksim Kita

Attachment Content-Type Size
0001-Allow-alter-type-delete-value-in-enum.patch text/x-diff 4.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Patrick REED 2020-10-07 14:27:22 Re: Prepared Statements
Previous Message Anastasia Lubennikova 2020-10-07 14:23:28 Re: MultiXact\SLRU buffers configuration