simplifying grammar for ALTER CONSTRAINT .. SET [NO] INHERIT

From: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Suraj Kharage <suraj(dot)kharage(at)enterprisedb(dot)com>
Subject: simplifying grammar for ALTER CONSTRAINT .. SET [NO] INHERIT
Date: 2025-03-25 16:02:49
Message-ID: 202503251602.vsxaehsyaoac@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2025-03-25 16:05:17 Re: simplifying grammar for ALTER CONSTRAINT .. SET [NO] INHERIT
Previous Message Noah Misch 2025-03-25 15:58:08 Re: AIO v2.5