Improve error message for duplicate labels in enum types

From: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Improve error message for duplicate labels in enum types
Date: 2025-07-03 15:04:02
Message-ID: 20250704000402.37e605ab0c59c300965a17ee@sraoss.co.jp
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Currently, when creating an enum type, duplicate labels are caught by a unique
index on pg_enum, resulting in a generic error message.

postgres=# create type t as enum ('a','b','a');
ERROR: duplicate key value violates unique constraint "pg_enum_typid_label_index"
DETAIL: Key (enumtypid, enumlabel)=(16418, a) already exists.

I propose adding an explicit check for duplicate labels during enum creation,
so that a more user-friendly and descriptive error message can be produced,
similar to what is already done in ALTER TYPE ... ADD VALUE
or ALTER TYPE ... RENAME VALUE .. TO ....

With the attached patch applied, the error message becomes:

ERROR: label "a" used more than once

Regards,
Yugo Nagata

--
Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>

Attachment Content-Type Size
0001-Improve-error-message-for-duplicate-labels-in-enum-t.patch text/x-diff 1.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo Nagata 2025-07-03 15:06:59 Re: Prevent internal error at concurrent CREATE OR REPLACE FUNCTION
Previous Message Ross Heaney 2025-07-03 15:00:29 Bloom Filter improvements in postgesql