BUG #5255: COUNT(*) returns wrong result with LEFT JOIN - Mailing list pgsql-bugs

From Matteo Beccati
Subject BUG #5255: COUNT(*) returns wrong result with LEFT JOIN
Date
Msg-id 200912251043.nBPAheeY048752@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #5255: COUNT(*) returns wrong result with LEFT JOIN
List pgsql-bugs
The following bug has been logged online:

Bug reference:      5255
Logged by:          Matteo Beccati
Email address:      php@beccati.com
PostgreSQL version: 8.5alpha3
Operating system:   NetBSD 5.0.1
Description:        COUNT(*)  returns wrong result with LEFT JOIN
Details:

Discovered this while fixing the php test suite to deal with 8.5 changes.

With the following data set a SELECT * query returns 1 rows, while SELECT
COUNT(*) returns 2.

CREATE TABLE a (id int PRIMARY KEY);
CREATE TABLE b (id int PRIMARY KEY, a_id int);
INSERT INTO a VALUES (0), (1);
INSERT INTO b VALUES (0, 0), (1, NULL);

test=# SELECT * FROM b LEFT JOIN a ON (b.a_id = a.id) WHERE (a.id IS NULL OR
a.id > 0);
 id | a_id | id
----+------+----
  1 |      |
(1 row)

test=# SELECT COUNT(*) FROM b LEFT JOIN a ON (b.a_id = a.id) WHERE (a.id IS
NULL OR a.id > 0);
 count
-------
     2
(1 row)

pgsql-bugs by date:

Previous
From: Devrim GÜNDÜZ
Date:
Subject: Re: BUG #5254: can't drop a table
Next
From: Tom Lane
Date:
Subject: Re: BUG #5255: COUNT(*) returns wrong result with LEFT JOIN