constraint -- one or the other column not null

From: "George Pavlov" <gpavlov(at)mynewplace(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: constraint -- one or the other column not null
Date: 2006-09-06 07:04:18
Message-ID: 8C5B026B51B6854CBE88121DBF097A86418B47@ehost010-33.exch010.intermedia.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dawid Kuroczko 2006-09-06 07:29:23 Re: constraint -- one or the other column not null
Previous Message Johannes Weberhofer, Weberhofer GmbH 2006-09-06 06:52:24 Postgres 8.1.4 sanity_check failed on SuSE 8.2