Re: uniqueness and null could benefit from a hint for dba

From: Tuomas Leikola <tuomas(dot)leikola(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: uniqueness and null could benefit from a hint for dba
Date: 2019-10-23 11:35:02
Message-ID: CALhc4GAq4H9DSeC7tU6Nkr34zykiA4g8WQ+suWmXSXTDApgHEA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

That is a nice design. You can create a regular unique index where
columns(s)s are not null and then filtered index(es) for the cases where
some of the unique columns are null.

However my point, specifically, was that if the document in question would
have offered alternative solutions, I personally would have been saved from
some frustration and an exercise in bad index design (I had 5 nullables
that need uniqueness for the null as well). Maybe it would help someone
else.

On Fri, Sep 27, 2019 at 7:37 PM Bruce Momjian <bruce(at)momjian(dot)us> wrote:

> On Wed, Sep 4, 2019 at 01:12:35PM +0000, PG Doc comments form wrote:
> > The following documentation comment has been logged on the website:
> >
> > Page: https://www.postgresql.org/docs/11/indexes-unique.html
> > Description:
> >
> > Sometimes it is convenient to create an unique index that considers NULL
> > values equal. Designating a "zero" value for those rows might not be
> > feasible, for example due to a foreign key.
> >
> > The documentation currently only states that unique indexes do not
> consider
> > NULLs equal. It might be good to offer workarounds, like indexing a
> coalesce
> > function, if scans are not the reason for the index, but the uniqueness
> > constraint.
>
> I did write a blog entry about this:
>
> https://momjian.us/main/blogs/pgblog/2017.html#April_3_2017
>
> Does that help?
>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
> EnterpriseDB http://enterprisedb.com
>
> + As you are, so once was I. As I am, so you will be. +
> + Ancient Roman grave inscription +
>

--
- Tuomas

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2019-10-23 16:00:11 Log Rotation Documentation Update
Previous Message Peter Eisentraut 2019-10-19 16:54:10 Use proper em and en dashes