Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UvZIn-0000vo-QF for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Jul 2013 20:41:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1UvZIm-0000zj-Vx for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Jul 2013 20:41:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UvZIk-0000za-Vw for pgsql-bugs@postgresql.org; Sat, 06 Jul 2013 20:41:51 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UvZIf-0004gj-UJ for pgsql-bugs@postgresql.org; Sat, 06 Jul 2013 20:41:48 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UvZIe-0004rt-NO for pgsql-bugs@postgresql.org; Sat, 06 Jul 2013 20:41:45 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.80) (envelope-from ) id 1UvZIZ-0003LO-DK for pgsql-bugs@postgresql.org; Sat, 06 Jul 2013 20:41:39 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: BUG #8287: select distinct / select group by - Invalid result To: pgsql-bugs@postgresql.org From: lindebg@gmail.com Message-Id: Date: Sat, 06 Jul 2013 20:41:39 +0000 X-Pg-Spam-Score: -1.0 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 8287 Logged by: Jacek Email address: lindebg@gmail.com PostgreSQL version: 9.2.4 Operating system: Debian x64 / Windows 8 x64 Description: I wanted to report an incorrect execution of the query SELECT DISTINCT... : Example: create table machines ( machineid int primary key, machinename varchar not null, editdate timestamp, deleted boolean ); insert into machines(machineid, machinename, deleted, editdate) values (1, 'test', false, null); create table commands ( commandid int primary key, command varchar not null, machineid int not null references machines(machineid) on delete cascade, resultdate timestamp ); insert into commands(commandid, machineid, command, resultdate) values (1, 1, 'command1', '2011-03-25 13:40:58.430'), (2, 1, 'command2', null), (3, 1, 'command3', '2012-04-05 21:22:23.111'), (4, 1, 'command1', null), (5, 1, 'command1', '2011-04-11 23:17:09.113'); create table commandsaddit ( commandid int primary key references commands(commandid) on delete cascade, param1 varchar, param2 varchar ); create view vmachinesall as select hs.machineid, hs.machinename, hs.editdate, case when hs.deleted then hs.editdate else null::timestamp end as deleteddate from machines hs; create view vmachines as select hs.machineid, hs.machinename, hs.editdate from vmachinesall hs where (hs.deleteddate is null); create view vcommands as select t.commandid, case when (t.resultdate is null) then 'Processing'::varchar when (a.commandid is not null) then 'Ok 1'::varchar else 'Ok 2'::varchar end as status from commands t inner join vmachines h on t.machineid = h.machineid left join commandsaddit a on t.commandid = a.commandid; -- example: select distinct status from vcommands; -- RESULT: -- Processing -- Ok 2 select distinct status from vcommands where status = 'xxx'; -- any value -- or select status from vcommands where status = 'xxx' -- any value group by status; -- RESULT: -- Ok 2 -- Processing -- Ok 2 -- Processing -- Ok 2 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs