Unique indices and nulls - Mailing list pgsql-novice

From Roland Roberts
Subject Unique indices and nulls
Date
Msg-id m2y9a9zigj.fsf@kuiper.rlent.pnet
Whole thread Raw
Responses Re: Unique indices and nulls  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
I see in the documentation that a unique index does not place any
constraints on the number of nulls in a table.  In my case, I have a
table with has four columns (plus other data) where that combination
of 4 columns should be unique.

    (catalog, entry, suffix, component)

forms a unique tuple.  In most (but not all) cases, (catalog, entry)
is unique and suffix and component will both be null.  In those cases,
it is common to have an entry with (catalog, entry, null, null), as
well as multiple entries with (catalog, entry, suffix, component).

But there should never be more than one entry with (catalog, entry,
null, null).

Is there any way I can enforce this?  Am I going to have to write a
trigger to check for duplicates?

roland
--
               PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD                             RL Enterprises
roland@rlenter.com                     76-15 113th Street, Apt 3B
roland@astrofoto.org                       Forest Hills, NY 11375

pgsql-novice by date:

Previous
From: rmit.test2115@gmail.com
Date:
Subject: [NOVICE] pl/pgsql and returns timestamp type
Next
From: Tom Lane
Date:
Subject: Re: Unique indices and nulls