Re: Check constraint

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Richard Huxton <dev(at)archonet(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 17:28:57
Message-ID: 20040317092711.D23707@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 17 Mar 2004, Richard Huxton wrote:

> On Wednesday 17 March 2004 12:03, Francisco Reyes 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.

Actually, shouldn't a table level check constraint be able to do this with
something like:
check (purchase_type!=3 or comment is not null)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Wood 2004-03-17 17:30:20 Re: Check constraint
Previous Message Richard Huxton 2004-03-17 17:26:01 Re: Smallint - Integer Casting Problems in Plpgsql functions