public inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
From: Jim Jones <jim.jones@uni-muenster.de>
To: Andreas Karlsson <andreas@proxel.se>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Prevent setting NO INHERIT on partitioned not-null constraints
Date: Thu, 21 May 2026 17:01:51 +0200
Message-ID: <24bfd6b7-d566-490c-812f-c61c9eb2ef69@uni-muenster.de> (raw)
In-Reply-To: <ecc985ad-6ec1-4094-a315-317943ca5f3f@proxel.se>
References: <ecc985ad-6ec1-4094-a315-317943ca5f3f@proxel.se>

Hi Andreas

On 20/05/2026 21:25, Andreas Karlsson wrote:
> Me and Joel found a bug when working on another patch. We noticed that
> you cannot create not-null constraints with NO INHEIRT set on
> partitioned tables, but you can actually set it later by using ALTER
> CONSTRAINT. This must be an oversight so I have attached a patch which
> adds a check to prevent this.
> 
> The SQL below should give an error but does not:
> 
> CREATE TABLE t (
>   a int,
>   CONSTRAINT a_is_not_null NOT NULL a
> ) PARTITION BY LIST (a);
> 
> ALTER TABLE t ALTER CONSTRAINT a_is_not_null NO INHERIT;

+1 for the fix.

postgres=# CREATE TABLE t (
  a int,
  CONSTRAINT a_is_not_null NOT NULL a
) PARTITION BY LIST (a);
CREATE TABLE
postgres=# ALTER TABLE t ALTER CONSTRAINT a_is_not_null NO INHERIT;
ERROR:  not-null constraint "a_is_not_null" on partitioned table "t"
cannot be NO INHERIT

The errcode is most likely wrong:

ERRCODE_WRONG_OBJECT_TYPE -> ERRCODE_FEATURE_NOT_SUPPORTED

At least it is inconsistent with an equivalent check in parse_utilcmd.c:

if (cxt->ispartitioned && constraint->is_no_inherit)
  ereport(ERROR,
	  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
          errmsg("not-null constraints on partitioned tables cannot be
NO INHERIT"));

Thanks!

Best, Jim







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-hackers@postgresql.org
  Cc: jim.jones@uni-muenster.de, andreas@proxel.se, pgsql-hackers@lists.postgresql.org
  Subject: Re: Prevent setting NO INHERIT on partitioned not-null constraints
  In-Reply-To: <24bfd6b7-d566-490c-812f-c61c9eb2ef69@uni-muenster.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox