Re: Questions concerning check constraints - Mailing list pgsql-general

From hubert depesz lubaczewski
Subject Re: Questions concerning check constraints
Date
Msg-id 20071102113044.GA20336@depesz.com
Whole thread Raw
In response to Questions concerning check constraints  ("Christian Rengstl" <Christian.Rengstl@klinik.uni-regensburg.de>)
List 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)

pgsql-general by date:

Previous
From: Oleg Bartunov
Date:
Subject: Re: Improve Search
Next
From: "Filip Rembiałkowski"
Date:
Subject: Re: Calculation for Max_FSM_pages : Any rules of thumb?