Re: Rows violating Foreign key constraint exists - Mailing list pgsql-general

From Nandakumar M
Subject Re: Rows violating Foreign key constraint exists
Date
Msg-id CANcFUu4YXJjHx43YLa4hhGobz9sqrmjuw3sLK+2nEYF_23A6YA@mail.gmail.com
Whole thread Raw
In response to Re: Rows violating Foreign key constraint exists  (Nandakumar M <m.nanda92@gmail.com>)
List 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



pgsql-general by date:

Previous
From: Nandakumar M
Date:
Subject: Re: Rows violating Foreign key constraint exists
Next
From: Tom Lane
Date:
Subject: Re: Rows violating Foreign key constraint exists