Skip site navigation (1) Skip section navigation (2)

Re: CHECK vs BEFORE trigger

From: brew(at)theMode(dot)com
To: Keith Worthington <keithw(at)narrowpathinc(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: CHECK vs BEFORE trigger
Date: 2005-04-22 21:18:38
Message-ID: Pine.BSF.4.58.0504221703150.87766@themode.com (view raw or flat)
Thread:
Lists: pgsql-novice
Keith....

> I am about to create a new table that will store among other things two
> dimensions.  The user requires that the smaller of the two dimesions always be
> referred to as the width.
>
> As I see it I can either implement a CHECK constraint and handle the error or
> implement a BEFORE INSERT OR UPDATE trigger that checks the two values and
> switches them if necessary.

I like your trigger solution.  The CHECK would then be redundant and not
neccessary.

However, the CHECK with an error message might be a good solution if you
think the user has his data mixed up beyond just swapping the length and
width, maybe he jumped to the next row on one dimension and is about to
enter a fictitious situation and an error message might warn him so he
could correct the data.

I think it depends on your user situation and what possible mistakes they
might make.

brew

 ==========================================================================
                  Strange Brew   (brew(at)theMode(dot)com)
  Check out my Stock Option Covered Call website  http://www.callpix.com
     and my Musician's Online Database Exchange http://www.TheMode.com
 ==========================================================================


In response to

pgsql-novice by date

Next:From: Michael FuhrDate: 2005-04-22 21:21:20
Subject: Re: SSL use
Previous:From: Mike OxfordDate: 2005-04-22 21:06:02
Subject: Re: char or int vs varchar

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group