Re: CHECK constraint

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: CHECK constraint
Дата
Msg-id 3E70A5C6.70401@joeconway.com
обсуждение исходный текст
Ответ на Re: CHECK constraint  (Ben Clewett <B.Clewett@roadrunner.uk.com>)
Ответы Re: CHECK constraint  (Ben Clewett <B.Clewett@roadrunner.uk.com>)
Re: CHECK constraint  (Ben Clewett <B.Clewett@roadrunner.uk.com>)
Список pgsql-novice
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



В списке pgsql-novice по дате отправления:

Предыдущее
От: "Marcus Andree S. Magalhaes"
Дата:
Сообщение: Re: Permission Denied
Следующее
От: "Marjee Kangas"
Дата:
Сообщение: Getting Started!?