pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Kashmira Patel (kupatel) <kupatel@cisco.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Question about check constraints
Date: Fri, 27 Jan 2006 17:40:22 -0700
Message-ID: <20060128004022.GA20476@winnie.fuhr.org> (raw)
In-Reply-To: <18AE59788A3FC640A367E5652E664D8001731288@xmb-sjc-237.amer.cisco.com>
References: <18AE59788A3FC640A367E5652E664D8001731288@xmb-sjc-237.amer.cisco.com>

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



view thread (6+ messages)  latest in thread

Message-ID: <20060128004022.GA20476@winnie.fuhr.org>
Permalink:  ../20060128004022.GA20476@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20060128004022.GA20476@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mike@fuhr.org, kupatel@cisco.com
  Subject: Re: Question about check constraints
  In-Reply-To: <20060128004022.GA20476@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox