help writing a constraint - Mailing list pgsql-general

From Gregory Seidman
Subject help writing a constraint
Date
Msg-id 20020811195319.GA10871@cs.brown.edu
Whole thread Raw
Responses Re: help writing a constraint
List 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


pgsql-general by date:

Previous
From: "Cornelia Boenigk"
Date:
Subject: Re: libpq
Next
From: Alvaro Herrera
Date:
Subject: Re: help writing a constraint