Thread: bogus error message for ALTER TABLE ALTER CONSTRAINT

bogus error message for ALTER TABLE ALTER CONSTRAINT

From
Álvaro Herrera
Date:
I just discovered that trying to set a foreign key as NO INHERIT in
ALTER TABLE ALTER CONSTRAINT returns an absurd error message:

create table pk (a int primary key);
create table fk (a int references pk);

alter table fk alter constraint fk_a_fkey deferrable, alter constraint fk_a_fkey no inherit;
ERROR:  ALTER CONSTRAINT statement constraints cannot be marked NO INHERIT

The explanation is that somebody misunderstood what must be given to
processCASbits in 2013.  The intended message is:
  ERROR:  FOREIGN KEY constraints cannot be marked NO INHERIT

Here's the fix along with some additional cleanup.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/

Attachment

Re: bogus error message for ALTER TABLE ALTER CONSTRAINT

From
Nathan Bossart
Date:
On Tue, Mar 04, 2025 at 07:22:22PM +0100, Álvaro Herrera wrote:
> I just discovered that trying to set a foreign key as NO INHERIT in
> ALTER TABLE ALTER CONSTRAINT returns an absurd error message:
> 
> create table pk (a int primary key);
> create table fk (a int references pk);
> 
> alter table fk alter constraint fk_a_fkey deferrable, alter constraint fk_a_fkey no inherit;
> ERROR:  ALTER CONSTRAINT statement constraints cannot be marked NO INHERIT
> 
> The explanation is that somebody misunderstood what must be given to
> processCASbits in 2013.  The intended message is:
>   ERROR:  FOREIGN KEY constraints cannot be marked NO INHERIT
> 
> Here's the fix along with some additional cleanup.

LGTM

-- 
nathan



Re: bogus error message for ALTER TABLE ALTER CONSTRAINT

From
Álvaro Herrera
Date:
On 2025-Mar-04, Nathan Bossart wrote:

> On Tue, Mar 04, 2025 at 07:22:22PM +0100, Álvaro Herrera wrote:
> > I just discovered that trying to set a foreign key as NO INHERIT in
> > ALTER TABLE ALTER CONSTRAINT returns an absurd error message:

> > Here's the fix along with some additional cleanup.
> 
> LGTM

Many thanks for the quick look.  Pushed now.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
Thou shalt check the array bounds of all strings (indeed, all arrays), for
surely where thou typest "foo" someone someday shall type
"supercalifragilisticexpialidocious" (5th Commandment for C programmers)



Re: bogus error message for ALTER TABLE ALTER CONSTRAINT

From
Tom Lane
Date:
=?utf-8?Q?=C3=81lvaro?= Herrera <alvherre@alvh.no-ip.org> writes:
> I just discovered that trying to set a foreign key as NO INHERIT in
> ALTER TABLE ALTER CONSTRAINT returns an absurd error message:
> create table pk (a int primary key);
> create table fk (a int references pk);
> alter table fk alter constraint fk_a_fkey deferrable, alter constraint fk_a_fkey no inherit;
> ERROR:  ALTER CONSTRAINT statement constraints cannot be marked NO INHERIT

> The explanation is that somebody misunderstood what must be given to
> processCASbits in 2013.  The intended message is:
>   ERROR:  FOREIGN KEY constraints cannot be marked NO INHERIT

Hmm.  I agree that "ALTER CONSTRAINT statement" is off the
mark here, but I'm not convinced that "FOREIGN KEY" is entirely
on-point either.  The grammar has no way of knowing what kind of
constraint is being targeted.  I do see that ATExecAlterConstraint
currently rejects every other kind of constraint, but do we need
to think of a more generic phrase?

            regards, tom lane