Re: ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED - Mailing list pgsql-hackers

From Simon Riggs
Subject Re: ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED
Date
Msg-id 1295003750.12442.9.camel@ebony
Whole thread Raw
In response to Re: ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED  (Peter Geoghegan <peter.geoghegan86@gmail.com>)
Responses Re: ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED  (Jim Nasby <jim@nasby.net>)
REVIEW: ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED  (Marko Tiikkaja <marko.tiikkaja@cs.helsinki.fi>)
Re: ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On Mon, 2010-12-13 at 17:15 +0000, Peter Geoghegan wrote:
> On 13 December 2010 16:08, Robert Haas <robertmhaas@gmail.com> wrote:
> > On Mon, Dec 13, 2010 at 10:49 AM, Simon Riggs <simon@2ndquadrant.com> wrote:
> >> 2. pg_validate_foreign_key('constraint name');
> >> Returns immediately if FK is valid
> >> Returns SETOF rows that violate the constraint, or if no rows are
> >> returned it updates constraint to show it is now valid.
> >> Lock held: AccessShareLock
> >
> > I'm less sure about this part.  I think there should be a DDL
> > statement to validate the foreign key.  The "return the problem" rows
> > behavior could be done some other way, or just left to the user to
> > write their own query.
>
> +1. I think that a DDL statement is more appropriate, because it makes
> the process sort of symmetrical.

Patch to implement the proposed feature attached, for CFJan2011.

2 sub-command changes:

ALTER TABLE foo ADD FOREIGN KEY fkoo ... NOT VALID;

ALTER TABLE foo VALIDATE CONSTRAINT fkoo;

--
 Simon Riggs           http://www.2ndQuadrant.com/books/
 PostgreSQL Development, 24x7 Support, Training and Services


Attachment

pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Recovery control functions
Next
From: Magnus Hagander
Date:
Subject: Re: Streaming base backups