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

Re: CHECK constraint

From: Ben Clewett <B(dot)Clewett(at)roadrunner(dot)uk(dot)com>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: paul(at)entropia(dot)co(dot)uk, pgsql-novice(at)postgresql(dot)org
Subject: Re: CHECK constraint
Date: 2003-03-13 15:55:33
Message-ID: 3E70A9F5.30809@roadrunner.uk.com (view raw or flat)
Thread:
Lists: pgsql-novice
Bloody-A that's perfect!

Elegent, readable, controlable.  And, unlike the CHECK ( foo IN ( SELECT 
.. ), it'd dynamic as well...

Ben

Joe Conway wrote:
> Ben Clewett wrote:
> 
>> Is this possible??  Should I cut-and-run here and do the coding in 
>> application space?
> 
> 
> How 'bout:
> 
> CREATE TABLE bar (
>   id int4 NOT NULL,
>   live bool
> );
> 
> insert into bar values(1,'t');
> insert into bar values(2,'f');
> 
> CREATE OR REPLACE FUNCTION check_bar(int4) RETURNS bool AS'
>   SELECT live FROM bar WHERE id = $1
> ' language 'sql' STABLE STRICT;
> 
> CREATE TABLE foo (
>   id int4 NOT NULL CHECK (check_bar(id))
> );
> 
> regression=# insert into foo values(1);
> INSERT 1336840 1
> regression=# insert into foo values(2);
> ERROR:  ExecInsert: rejected due to CHECK constraint "foo_id" on "foo"
> 
> HTH,
> 
> Joe
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
> 



In response to

pgsql-novice by date

Next:From: Bryan EncinaDate: 2003-03-13 16:06:20
Subject: Re: Getting Started!?
Previous:From: Marjee KangasDate: 2003-03-13 15:49:53
Subject: Getting Started!?

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