From: | Joel Burton <joel(at)joelburton(dot)com> |
---|---|
To: | Nick Haw <nick(dot)haw(at)operagrp(dot)com> |
Cc: | "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>, "'pgsql-novice(at)postgresql(dot)org'" <pgsql-novice(at)postgresql(dot)org>, "'pgsql-novice(at)postgresql(dot)org'" <pgsql-novice(at)postgresql(dot)org>, "'pgsql-novice(at)postgresql(dot)org'" <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Conditional constraint? |
Date: | 2002-03-08 19:44:10 |
Message-ID: | Pine.LNX.4.30.0203081442170.11421-100000@temp.joelburton.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-novice |
On Fri, 8 Mar 2002, Nick Haw wrote:
> Hi there, I have a problem that I can't fathom out.
>
> What I want to do is make a field so that it requires a value after a change
> in another field to a particular value. Is this possible with the ADD
> CONSTRAINT command, or will I have to make a custom function and use a
> trigger.
As in
CREATE TABLE library_patrons
(id SERIAL PRIMARY KEY,
age int NOT NULL,
parents_phone VARCHAR(20) )
parents_phone could be blank, but if the patron is under 18, it should be
required?
You could make that the CONSTRAINT, however, when the age is changed, PG
won't automatically reconsider the constraint on parents_phone (unless new
data was changed in it)
So, yep, you'd have to use a trigger. Pretty straightforward to do,
though.
--
Joel BURTON | joel(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
Independent Knowledge Management Consultant
From | Date | Subject | |
---|---|---|---|
Next Message | Francisco Reyes | 2002-03-08 20:30:36 | Re: Is vacuum full lock like old's vacuum's lock? |
Previous Message | mdb | 2002-03-08 19:13:42 | Re: Temp Tables |
From | Date | Subject | |
---|---|---|---|
Next Message | Patrick Hatcher | 2002-03-08 19:58:38 | Re: FATAL 1: Database template0 not accepting connection? |
Previous Message | Joel Burton | 2002-03-08 19:41:45 | Re: FATAL 1: Database template0 not accepting connection? |