help writing a constraint

From: Gregory Seidman <gss+pg(at)cs(dot)brown(dot)edu>
To: PostgreSQL general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: help writing a constraint
Date: 2002-08-11 19:53:19
Message-ID: 20020811195319.GA10871@cs.brown.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table with a pair of columns that shouldn't both have values:

CREATE TABLE Foo (
id SERIAL not null,
hasBar integer default null REFERERENCES Bar,
hasBaz integer default null REFERERENCES Baz,
primary key (id)
);

I need to constrain this so that for any given row, it either hasBar or
hasBaz, or neither, but not both. I'm not entirely clear on how to write
constraints, though. Is the following correct (within the CREATE)?

CHECK (hasBar IS NULL OR hasBaz IS NULL)

--Greg

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2002-08-11 20:09:43 Re: [GENERAL] workaround for lack of REPLACE() function
Previous Message Cornelia Boenigk 2002-08-11 17:40:12 Re: libpq