pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: jo <jose.soares@sferacarta.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6669: unique index w/ multiple columns and NULLs
Date: Mon, 04 Jun 2012 09:19:56 -0500
Message-ID: <4FCC7DBC0200002500047FE8@gw.wicourts.gov> (raw)
In-Reply-To: <4FC86818.4080002@sferacarta.com>
References: <E1SZxsy-0001GO-JW@wrigleys.postgresql.org>
	<2870.1338521291@sss.pgh.pa.us>
	<4FC86818.4080002@sferacarta.com>

jo <jose.soares@sferacarta.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



view thread (11+ messages)  latest in thread

Message-ID: <4FCC7DBC0200002500047FE8@gw.wicourts.gov>
Permalink:  ../4FCC7DBC0200002500047FE8@gw.wicourts.gov/
Also on:    postgresql.org/message-id/4FCC7DBC0200002500047FE8@gw.wicourts.gov

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: Kevin.Grittner@wicourts.gov, jose.soares@sferacarta.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #6669: unique index w/ multiple columns and NULLs
  In-Reply-To: <4FCC7DBC0200002500047FE8@gw.wicourts.gov>
  References: <E1SZxsy-0001GO-JW@wrigleys.postgresql.org> <2870.1338521291@sss.pgh.pa.us> <4FC86818.4080002@sferacarta.com> <4FCC7DBC0200002500047FE8@gw.wicourts.gov>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox