Re: Rows violating Foreign key constraint exists

From: Nandakumar M <m(dot)nanda92(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Rows violating Foreign key constraint exists
Date: 2019-11-29 09:02:35
Message-ID: CANcFUu4YXJjHx43YLa4hhGobz9sqrmjuw3sLK+2nEYF_23A6YA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

> PG already allows a new FK to be created with ADD CONSTRAINT ... NOT
> VALID clause which can be validated later using ALTER TABLE ...
> VALIDATE CONSTRAINT.
> I guess what we are looking for here is the same but for existing FKs.
>
> i.e Something like
>
> `ALTER TABLE distributors ALTER CONSTRAINT distfk NOT VALID;`
> `ALTER TABLE distributors VALIDATE CONSTRAINT distfk;`
>

I was wrong about this. ADD CONSTRAINT ... NOT VALID just postpones
integrity existing on existing data.
There is no equivalent for that when altering an existing FK.

Maybe, DISABLE ALL TRIGGERS can mark the FKs as NOT VALID. ALTER TABLE
... VALIDATE CONSTRAINT would now report inconsistencies if any.
Also, VALIDATE CONSTRAINT would have to verify that the trigger
implementing FK is enabled.

Hope/unsure if this would not break backwards compatibility.

Regards,
Nanda

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-11-29 15:23:25 Re: Rows violating Foreign key constraint exists
Previous Message Nandakumar M 2019-11-29 08:15:37 Re: Rows violating Foreign key constraint exists