Re: CREATE DOMAIN create two not null constraints

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: CREATE DOMAIN create two not null constraints
Date: 2025-06-01 16:13:20
Message-ID: 202506011613.7hr4tuji7pl6@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2025-Jun-01, jian he wrote:

> hi.
>
> CREATE DOMAIN int_domain1 AS INT CONSTRAINT nn1 NOT NULL CONSTRAINT
> nn2 NOT NULL;
>
> will install two not-null pg_constraint entries.
> we should have only one?

Hmm, I think it would be more consistent to reject the case of duplicate
constraints, instead of silently ignoring it. So you'd do it in the
loop that checks for constraints before creating anything, like

diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 45ae7472ab5..b5daa61260b 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -944,6 +944,12 @@ DefineDomain(ParseState *pstate, CreateDomainStmt *stmt)
errcode(ERRCODE_SYNTAX_ERROR),
errmsg("conflicting NULL/NOT NULL constraints"),
parser_errposition(pstate, constr->location));
+
+ if (nullDefined)
+ ereport(ERROR,
+ errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("redundant NOT NULL constraint definition"));
+
if (constr->is_no_inherit)
ereport(ERROR,
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"Porque Kim no hacía nada, pero, eso sí,
con extraordinario éxito" ("Kim", Kipling)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jiří Kavalík 2025-06-01 16:58:05 [PATCH] Support for basic ALTER TABLE progress reporting.
Previous Message Peter Geoghegan 2025-06-01 16:06:51 RelationGetNumberOfBlocks called before vacuum_get_cutoffs