From: Álvaro Herrera <alvherre@alvh.no-ip.org>
To: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Suraj Kharage <suraj.kharage@enterprisedb.com>
Subject: simplifying grammar for ALTER CONSTRAINT .. SET [NO] INHERIT
Date: Tue, 25 Mar 2025 17:02:49 +0100
Message-ID: <202503251602.vsxaehsyaoac@alvherre.pgsql> (raw)
With commit f4e53e10b6ce we introduced a way to flip the NO INHERIT bit
on not-null constraints. However, because of the way the grammar
dealt with ALTER CONSTRAINT, we were too blind to see a way to implement
it using the existing production. It turns out that we can remove it,
so the commands would be
ALTER TABLE tab ALTER CONSTRAINT constr INHERIT
ALTER TABLE tab ALTER CONSTRAINT constr NO INHERIT
i.e. the word SET is no longer needed.
Do people find this better?
A proposed patch is attached. One thing not fully clear to me is that
now the entry for ALTER CONSTRAINT in the sgml docs is awkward, because
it describes the INHERIT flag separate from the deferrability flags.
After this patch, it's a bit more obvious that the error messages we're
throwing now aren't ideal:
55432 18devel 2953943=# create table foo (a int not null);
CREATE TABLE
55432 18devel 2953943=# alter table foo alter constraint foo_a_not_null no inherit deferrable;
ERROR: constraint "foo_a_not_null" of relation "foo" is not a foreign key constraint
55432 18devel 2953943=# create table bar (a int primary key references bar);
CREATE TABLE
55432 18devel 2953943=# alter table bar alter constraint bar_a_fkey deferrable no inherit;
ERROR: constraint "bar_a_fkey" of relation "bar" is not a not-null constraint
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Saca el libro que tu religión considere como el indicado para encontrar la
oración que traiga paz a tu alma. Luego rebootea el computador
y ve si funciona" (Carlos Duclós)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: alvherre@alvh.no-ip.org, suraj.kharage@enterprisedb.com
Subject: Re: simplifying grammar for ALTER CONSTRAINT .. SET [NO] INHERIT
In-Reply-To: <202503251602.vsxaehsyaoac@alvherre.pgsql>
References: <202503251602.vsxaehsyaoac@alvherre.pgsql>
* 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