Re: CHECK constraint

Поиск
Список
Период
Сортировка
Искать
От
Ben Clewett
Тема
Re: CHECK constraint
Дата
Msg-id
3E70A9F5.30809@roadrunner.uk.com
Ответ на
Список
Дерево обсуждения
User Privilege table Yovko Ilchev Yovkov <yyovkov@yovko.net>
Version Number Ben Clewett <B.Clewett@roadrunner.uk.com>
Re: Version Number Bruno Wolff III <bruno@wolff.to>
CHECK constraint Ben Clewett <B.Clewett@roadrunner.uk.com>
Re: CHECK constraint "paul butler" <paul@entropia.co.uk>
Re: CHECK constraint Ben Clewett <B.Clewett@roadrunner.uk.com>
Re: CHECK constraint Joe Conway <mail@joeconway.com>
Re: CHECK constraint Ben Clewett <B.Clewett@roadrunner.uk.com>
Re: CHECK constraint Ben Clewett <B.Clewett@roadrunner.uk.com>
Re: Version Number Joe Conway <mail@joeconway.com>
Re: Version Number Jason Earl <jason.earl@simplot.com>
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@postgresql.org so that your
> message can get through to the mailing list cleanly
> 


В списке pgsql-novice по дате отправления
От: Marjee Kangas
Дата:
Сообщение: Getting Started!?
От: Bryan Encina
Дата:
Сообщение: Re: Getting Started!?
FAQ