Re: Questions concerning check constraints

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Christian Rengstl <Christian(dot)Rengstl(at)klinik(dot)uni-regensburg(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Questions concerning check constraints
Date: 2007-11-02 11:30:44
Message-ID: 20071102113044.GA20336@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Nov 02, 2007 at 10:04:06AM +0100, Christian Rengstl wrote:
> 1) Is it possible to refer to a column in a different table, ie
> entering a value in mytable.x should only be allowed if mytable2.y=1 for
> example? I know that it is possible to use triggers to do that, but I
> think adding a simple check constraint might be simpler.

you would need to make a wrapper function for the actual checking, and
then add check (function(column) = true) or something like this.

> 2) Is it possible to issue custom error messages in case a constraint
> is violated?

if you have function based checks - sure, "raise exception"

depesz

--
quicksil1er: "postgres is excellent, but like any DB it requires a
highly paid DBA. here's my CV!" :)
http://www.depesz.com/ - blog dla ciebie (i moje CV)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Filip Rembiałkowski 2007-11-02 11:53:59 Re: Calculation for Max_FSM_pages : Any rules of thumb?
Previous Message Oleg Bartunov 2007-11-02 10:08:58 Re: Improve Search