Re: BUG #6669: unique index w/ multiple columns and NULLs

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "jo" <jose(dot)soares(at)sferacarta(dot)com>,"Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #6669: unique index w/ multiple columns and NULLs
Date: 2012-06-04 14:19:56
Message-ID: 4FCC7DBC0200002500047FE8@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

jo <jose(dot)soares(at)sferacarta(dot)com> wrote:

> Thanks for the explanation about standard sql.
> The goodness of it must be accepted by faith. :-)

Not if you have the stamina to fight your way through the standards
documents. ;-)

> I still have a doubt about the result of the GROUP BY clause.
> It seems to me that there's an inconsistence between the GROUP BY
> clause and the unique index.
> The GROUP BY clause, consider NULLs as known and equal values
> while the index unique constraint consider NULLs as unknown values
> and not equals between them.
> Don't you think, there's an inconsistence here?

I think these behaviors are required by the standard. The
PostgreSQL community generally feels pretty strongly that when
standard syntax is accepted, standard semantics are provided.

While the standard is often criticized, in this case I think it
makes sense. The meaning of NULL is traditionally "UNKNOWN or NOT
APPLICABLE". It would not make sense to have a hard prohibition of
two rows which only *might* be relating to the same object. In the
"NOT APPLICABLE" case it would make sense, but unfortunately SQL has
no way to distinguish which meaning NULL has. On the other hand,
aggregates like counts might be very useful -- it is often useful to
know not only how many rows have each of the known values, but how
many are missing a value.

Have you looked at whether an exclusion constraint would serve your
needs here?

-Kevin

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2012-06-04 15:05:52 Re: BUG #6669: unique index w/ multiple columns and NULLs
Previous Message pgagarinov 2012-06-04 13:00:45 Re: Calling xlst_process with certain arguments causes server crash