Re: CREATE DOMAIN create two not null constraints - Mailing list pgsql-hackers

From jian he
Subject Re: CREATE DOMAIN create two not null constraints
Date
Msg-id CACJufxFrAhpTjfsaKWq+uuo=edEsOu0ZO7f_T6dEQh7N7putNA@mail.gmail.com
Whole thread Raw
In response to Re: CREATE DOMAIN create two not null constraints  (Álvaro Herrera <alvherre@kurilemu.de>)
List pgsql-hackers
On Mon, Jun 2, 2025 at 12:13 AM Álvaro Herrera <alvherre@kurilemu.de> wrote:
>
> 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),

I don't have a preference.
error out would be fine, since it's a corner case.



pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: Re: ALTER TABLE ALTER CONSTRAINT misleading error message
Next
From: Amul Sul
Date:
Subject: Re: Foreign key validation failure in 18beta1