Re: [BUGS] General Bug Report: GROUP BY with NULL not done properly(Oracle8 & DB/2 do this completely different)

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: secret(at)kearneydev(dot)com
Cc: pgsql-bugs(at)postgreSQL(dot)org
Subject: Re: [BUGS] General Bug Report: GROUP BY with NULL not done properly(Oracle8 & DB/2 do this completely different)
Date: 1999-07-07 18:10:03
Message-ID: 199907071810.OAA05287@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


Looks like this is fixed in 6.5.

test=> SELECT a,sum(b) FROM z GROUP BY a;
a|sum
-+---
1| 6
| 4
(2 rows)

>
> ============================================================================
> POSTGRESQL BUG REPORT TEMPLATE
> ============================================================================
>
>
> Your name :
> Your email address : secret(at)kearneydev(dot)com
>
> Category : runtime: back-end: SQL
> Severity : non-critical
>
> Summary: GROUP BY with NULL not done properly(Oracle8 & DB/2 do this completely different)
>
> System Configuration
> --------------------
> Operating System : Linux 2.2.7 Redhat 5.2
>
> PostgreSQL version : 6.4.2
>
> Compiler used : 2.7.2.3
>
> Hardware:
> ---------
> Linux tau.kearneydev.com 2.2.7 #3 Thu Apr 29 10:10:41 EDT 1999 i686 unknown
>
> Versions of other tools:
> ------------------------
>
>
> --------------------------------------------------------------------------
>
> Problem Description:
> --------------------
> The appearance of NULL in a table where a GROUP BY clause is
> used causes the behavior of returning 1 line for every NULL.
> Both Oracle8 and DB/2 perform this as I would expect. IE
> a,b
> 1,1
> 1,2
> NULL,1
> NULL,2
>
> SELECT a,sum(b) GROUP BY a returns on Postgres:
> 1,3
> NULL,1
> NULL,2
>
> On Oracle8, DB/2, etc.:
> 1,3
> NULL,3
>
> Cut&paste from Oracle8:
> SQL> select * from z;
>
> A B
> --------- ---------
> 1 1
> 1 2
> 5
> 10
>
> SQL> select a,sum(b) from z group by a;
>
> A SUM(B)
> --------- ---------
> 1 3
> 15
>
> SQL>
>
> --------------------------------------------------------------------------
>
> Test Case:
> ----------
> CREATE TABLE z(a int4,b int4);
> INSERT INTO z values (1,2);
> INSERT INTO z VALUES (1,1);
> INSERT INTO z(b) VALUES (1);
> INSERT INTO z(b) VALUES (2);
> SELECT a,sum(b) FROM z GROUP BY a;
>
>
> --------------------------------------------------------------------------
>
> Solution:
> ---------
> For whatever reason I've observed many times that NULL<>NULL
> under PostgreSQL, I've had to include many clauses in my
> SQL statements to make up for this, perhaps if this was
> corrected it would function properly.
>
> --------------------------------------------------------------------------
>
>
>

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 1999-07-08 02:53:27 Re: [BUGS] General Bug Report: Files greater than 1 GB are created while sorting
Previous Message Bruce Momjian 1999-07-07 02:20:38 Re: [BUGS] General Bug Report: Handling of quoted identifiers and sequences