Re: creating CHECK constraints as NOT VALID - Mailing list pgsql-hackers

From David Fetter
Subject Re: creating CHECK constraints as NOT VALID
Date
Msg-id 20110601014208.GC13296@fetter.org
Whole thread Raw
In response to creating CHECK constraints as NOT VALID  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Responses Re: creating CHECK constraints as NOT VALID
List pgsql-hackers
On Tue, May 31, 2011 at 12:04:07PM -0400, Alvaro Herrera wrote:
> This patch allows you to initially declare a CHECK constraint as NOT
> VALID, similar to what we already allow for foreign keys.  That is, you
> create the constraint without scanning the table and after it is
> committed, it is enforced for new rows; later, all rows are checked by
> running ALTER TABLE VALIDATE CONSTRAINT, which doesn't need
> AccessExclusive thus allowing for better concurrency.
> 
> The trickiest bit here was realizing that unlike FKs, check constraints
> do inherit, and so needed special treatment for recursion.  Other than
> that I think this was pretty straightforward.
> 
> I intend to attempt to apply this to NOT NULL constraints as well, once
> the patch to add them to pg_constraint is in.
> 
> Thoughts?
> 
> This patch courtesy of Enova Financial.

Great stuff!

A colleague brought up an interesting idea that I think is worth
exploring for all NOT VALID constraints, to wit, is there some way
(via SQL) to find which rows violate which constraints?  I'm picturing
some kind of function that could be aggregated into some structure for
each violating row...

Cheers,
David.
-- 
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: creating CHECK constraints as NOT VALID
Next
From: Josh Kupershmidt
Date:
Subject: Re: Any idea for serializing INSERTING SERIAL column?