pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <bruce@momjian.us>
To: jo <jose.soares@sferacarta.com>
Cc: 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, 4 Jun 2012 11:05:52 -0400
Message-ID: <20120604150552.GB2352@momjian.us> (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>

On Fri, Jun 01, 2012 at 08:58:32AM +0200, jo wrote:
> Hi Tom,
> 
> Thanks for the explanation about standard sql.
> The goodness of it must be accepted by faith. :-)
> 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?

Yes, I can see your point.  I think GROUP BY is doing the best it can
with the NULL;  having it consider them as different would lead to long
output.  Also consider that COUNT(*) counts nulls, while COUNT(col) does
not:

	WITH null_test (col) AS
	(
	   SELECT 8
	   UNION ALL
	   SELECT NULL
	)
	SELECT COUNT(*) FROM null_test
	UNION ALL
	SELECT COUNT(col) FROM null_test;
	
	 count
	-------
	     2
	     1
	(2 rows)

COUNT(*) can't skip nulls because there is no specified column, but why
does COUNT(col) skip nulls --- again, inconsistent.

I think NULL is helpful for unknown values, and required as the output
of missing INSERT columns and unjoined outer join columns.  I think the
aggregates then did the best they could.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +



view thread (11+ messages)  latest in thread

Message-ID: <20120604150552.GB2352@momjian.us>
Permalink:  ../20120604150552.GB2352@momjian.us/
Also on:    postgresql.org/message-id/20120604150552.GB2352@momjian.us

 · 

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: bruce@momjian.us, jose.soares@sferacarta.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #6669: unique index w/ multiple columns and NULLs
  In-Reply-To: <20120604150552.GB2352@momjian.us>
  References: <E1SZxsy-0001GO-JW@wrigleys.postgresql.org> <2870.1338521291@sss.pgh.pa.us> <4FC86818.4080002@sferacarta.com> <20120604150552.GB2352@momjian.us>

* 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