pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve error message for duplicate labels when creating an enum
Date: Tue, 02 Sep 2025 17:51:11 +0000
Message-ID: <E1utVA0-000Bo3-0K@gemulon.postgresql.org> (raw)

Improve error message for duplicate labels when creating an enum type.

Previously, duplicate labels in CREATE TYPE AS ENUM were caught by
the unique index on pg_enum, resulting in a generic error message.
While this was evidently intentional, it's not terribly user-friendly,
nor consistent with the ALTER TYPE cases which take more care with
such errors.  This patch adds an explicit check to produce a more
user-friendly and descriptive error message.

A potential objection to this implementation is that it adds O(N^2)
work to the creation operation.  However, quick testing finds that
that's pretty negligible below 1000 enum labels, and tolerable even
at 10000.  So it doesn't really seem worth being smarter.

Author: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-by: Rahila Syed <rahilasyed90@gmail.com>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/20250704000402.37e605ab0c59c300965a17ee@sraoss.co.jp

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1b1960c8c9e81171efabdd9e3393b4eec1ffc477

Modified Files
--------------
src/backend/catalog/pg_enum.c      | 25 +++++++++++++++++++------
src/test/regress/expected/enum.out |  3 +++
src/test/regress/sql/enum.sql      |  3 +++
3 files changed, 25 insertions(+), 6 deletions(-)



Message-ID: <E1utVA0-000Bo3-0K@gemulon.postgresql.org>
Permalink:  ../E1utVA0-000Bo3-0K@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1utVA0-000Bo3-0K@gemulon.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-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Improve error message for duplicate labels when creating an enum
  In-Reply-To: <E1utVA0-000Bo3-0K@gemulon.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