Re: Question about check constraints - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: Question about check constraints
Date
Msg-id 20060128004022.GA20476@winnie.fuhr.org
Whole thread Raw
In response to Question about check constraints  ("Kashmira Patel \(kupatel\)" <kupatel@cisco.com>)
List pgsql-sql
On Fri, Jan 27, 2006 at 03:06:26PM -0800, Kashmira Patel (kupatel) wrote:
>   I have a table where two columns have two different check constraints
> associated with them. When I update one column, the check constraint on
> the other column is also executed. Is there a way to avoid this? I want
> to check only for the condition defined for the column being updated.

I don't think you can change this behavior: each CHECK constraint
is evaluated for the new row regardless of whether a particular
column changed or not.  However, you could enforce the constraints
with a trigger and skip checks where NEW.column is the same as
OLD.column.

Why the concern?  Are the checks expensive?  Do they have side
effects?  What do they do?

-- 
Michael Fuhr


pgsql-sql by date:

Previous
From: "Kashmira Patel \(kupatel\)"
Date:
Subject: Question about check constraints
Next
From: "Kashmira Patel \(kupatel\)"
Date:
Subject: Re: Question about check constraints