constraint -- one or the other column not null - Mailing list pgsql-general

From George Pavlov
Subject constraint -- one or the other column not null
Date
Msg-id 8C5B026B51B6854CBE88121DBF097A86418B47@ehost010-33.exch010.intermedia.net
Whole thread Raw
Responses Re: constraint -- one or the other column not null  ("Dawid Kuroczko" <qnex42@gmail.com>)
Re: constraint -- one or the other column not null  (Wayne Conrad <wconrad@yagni.com>)
List pgsql-general
I have two columns, both individually nullable, but a row needs to have
a value in one or the other. What is the best way to implement the
constraints? I currently have:

create table f (
  a int,
  b int,
  check (a + b is null),
  check (coalesce(a,b) is not null)
);

Is there a better way to do it?



--
George Pavlov
http://mynewplace.com
415.348.2010 desk
415.235.3180 mobile

pgsql-general by date:

Previous
From: "Johannes Weberhofer, Weberhofer GmbH"
Date:
Subject: Postgres 8.1.4 sanity_check failed on SuSE 8.2
Next
From: "Dawid Kuroczko"
Date:
Subject: Re: constraint -- one or the other column not null