Re: constraint -- one or the other column not null

From: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
To: "George Pavlov" <gpavlov(at)mynewplace(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: constraint -- one or the other column not null
Date: 2006-09-06 07:29:23
Message-ID: 758d5e7f0609060029x46dc5889g4342d43f84e554ee@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 9/6/06, George Pavlov <gpavlov(at)mynewplace(dot)com> wrote:
> 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?

Personally I woud simply put there
CHECK(a IS NOT NULL OR b IS NOT NULL)
which is probably the simplest form of your constraint. :)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Teodor Sigaev 2006-09-06 07:42:46 Re: ERROR: Gin doesn't support full scan due to it's awful
Previous Message George Pavlov 2006-09-06 07:04:18 constraint -- one or the other column not null