Re: [HACKERS] Re: [SQL] Oddities with NULL and GROUP BY

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: secret <secret(at)kearneydev(dot)com>, Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
Cc: pgsql-sql(at)postgreSQL(dot)org, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Re: [SQL] Oddities with NULL and GROUP BY
Date: 1999-05-19 15:44:32
Message-ID: l03130307b3688a1e21f0@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

At 18:28 +0300 on 19/05/1999, secret wrote:

> Sigh. PostgreSQL seems pretty inconsitant in this... GROUP BY with 1
>column
> produces NULLs grouped, with 2 colums it usually seems not to(although I
>somehow
> came up with an example where it did, grr... but lets ignore this since it's
> supposed to "not work" that way.)... Oracle8, DB/2, and Sybase all group
>NULLs
> together, for compatibility sake wouldn't it be reasonable for PostgreSQL
>to do
> the same? Else porting applications could fail miserably when one hits this
> inconsistency.

Please, please, the standard is clear about each of these things
separately. It absolutely says that nulls should be grouped together, and
it absolutely says that the comparison operator should not. It's true that
these things are not consistent, but for each operation, the standard is
quite clear on how it should be done.

In my opinion, there should be null comparison for internal operations, and
null comparison for the comparison operator. For this purpose, what
Postgres does now - return a NULL boolean if one of its operands is null -
is consistent with the standard. For GROUP BY and ORDER BY, they should be
compared equal, and for UNIQUE, they should not be compared.

UNIQUE has explicit mention of nulls in the standard.
ORDER BY has explicit mention of nulls in the standard.
GROUP BY has implicit mention of nulls, by using the term "distinct" which
is defined earlier and includes and explicit mention of nulls.
"=" has explicit mention of nulls in the standard.

And although they are not consistent (some are equal, some are not equal,
and some are unknown), they are covered in no uncertain terms.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-05-19 16:21:55 Re: [HACKERS] Off topic - ref spreadsheet
Previous Message Herouth Maoz 1999-05-19 15:31:19 Re: [HACKERS] Re: [SQL] Oddities with NULL and GROUP BY

Browse pgsql-sql by date

  From Date Subject
Next Message Willian Jakobs 1999-05-20 10:54:44 deleting all tables in the list
Previous Message Roberto Fichera 1999-05-19 15:44:03 Testing permissions