From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Gregory Wood <gwood(at)ewebengine(dot)com> |
Cc: | Francisco Reyes <lists(at)natserv(dot)com>, pgsql General List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Check constraint |
Date: | 2004-03-17 18:09:08 |
Message-ID: | 200403171809.08235.dev@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wednesday 17 March 2004 17:30, Gregory Wood wrote:
> >>I have a "comment" field in a table that I want populated if another
> >> field has a certain value. Is it possible to set a check constraint for
> >> this?
> >>
> >>Example:
> >>Let's say we have fields
> >>Purchase_type smallint check(purchase_type <4)
> >>comment varchar
> >>
> >>I need a check rule to something like (pseudo code)
> >>check (if purchase_type = 3 then NOT NULL comment)
> >
> > No - you'll want a BEFORE UPDATE/INSERT trigger. It shouldn't be
> > difficult to do though.
>
> I don't see why not:
>
> CHECK ((purchase_type <> 3) OR ((purchase_type = 3) AND comment IS NOT
> NULL))
Ah - I misread the original post. I thought Francisco was trying to
automatically copy the comment field when purchase_type=3.
Apologies, Francisco
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Valter | 2004-03-17 18:12:03 | Relation "xxxxx" does not exist - more info |
Previous Message | Rod K | 2004-03-17 18:07:15 | Re: Data Corruption in case of abrupt failure |