Re: CHECK constraint

From: Joe Conway <mail(at)joeconway(dot)com>
To: Ben Clewett <B(dot)Clewett(at)roadrunner(dot)uk(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:37:42
Message-ID: 3E70A5C6.70401@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Marjee Kangas 2003-03-13 15:49:53 Getting Started!?
Previous Message Marcus Andree S. Magalhaes 2003-03-13 15:35:56 Re: Permission Denied