Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 988A7B5DBE0 for ; Mon, 8 Aug 2011 12:31:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 07696-07 for ; Mon, 8 Aug 2011 15:31:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) by mail.postgresql.org (Postfix) with ESMTP id 2B6FFB5DBBF for ; Mon, 8 Aug 2011 12:31:43 -0300 (ADT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:In-Reply-To:References:Cc:To:From; bh=x91tFqCH2uo7WG+CyZRz4P3lgf1UejjY9cOffNFsLpo=; b=oanOcDL7pArAFDwqxdElb6/IGmxp0uj/UA7KQvsWDPhSY5iCYefF+tkDPl4R7vK/QfzlzGF4JH+KzyMVtJMpaRXT/pLLp0cYcdhNuNAYgM8xwligxqKTg26wwtfcmG8h; Received: from [180.183.160.156] (port=28817 helo=ws) by smtp16.mail.ru with asmtp id 1QqRnp-0000hp-00; Mon, 08 Aug 2011 19:31:42 +0400 From: "ai" To: "'Tom Lane'" , "'Kevin Grittner'" Cc: References: <201108081313.p78DDX6W021751@wwwmaster.postgresql.org> <4E3FA39B020000250003FC1F@gw.wicourts.gov> <25701.1312815692@sss.pgh.pa.us> In-Reply-To: <25701.1312815692@sss.pgh.pa.us> Subject: Re: BUG #6154: wrong result with nested left-joins Date: Mon, 8 Aug 2011 22:31:30 +0700 Message-ID: <01bc01cc55e0$4592ddf0$d0b899d0$@mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQKtBagl8fgbDVr+0xwL5rgFD0w44gLDzn4lAgnuvfiTK0UewA== Content-Language: ru X-Spam: Not detected X-Mras: Ok X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201108/69 X-Sequence-Number: 30881 Oops.. I just saw, that I send you "correct" (already with "workaround") sql-code instead of "wrong"...=20 my mistake =3D(( don't kill me - I spend too much time with this piece = of code today... But I'm sure that you got the point from my description of the = results... but just in case here is "wrong" (difference is in "SELECT sub3.key3, sub4.value2 FROM" ): SELECT * FROM ( SELECT 1 as key1 ) sub1 LEFT JOIN=20 ( SELECT sub3.key3, sub4.value2 FROM ( SELECT 1 as key3 ) sub3 LEFT JOIN=20 ( SELECT sub5.key5, COALESCE(sub6.value1, = 1) as value2 FROM ( SELECT 1 as key5 ) sub5 LEFT JOIN ( SELECT 1 as key6, value1 FROM ( SELECT NULL::integer as value1 ) sub7 WHERE false ) sub6 ON false ) sub4 ON sub4.key5=3Dsub3.key3 ) sub2 ON sub1.key1 =3D sub2.key3 =E1.=E9. -----Original Message----- From: Tom Lane [mailto:tgl@sss.pgh.pa.us]=20 Sent: Monday, August 08, 2011 10:02 PM To: Kevin Grittner Cc: listar; pgsql-bugs@postgresql.org Subject: Re: [BUGS] BUG #6154: wrong result with nested left-joins=20 "Kevin Grittner" writes: > "listar" wrote: >> PostgreSQL version: 8.4.5 >> Description: wrong result with nested left-joins =20 >> And this is the problem - value2 can't be NULL because of COALESCE in = >> sub4 (at least I think that it can't be =3D)) =20 > This works correctly in release 9.0.4 and development HEAD. I don't=20 > still have any machines handy which are running 8.4, but you might=20 > want to try it on the latest bug-fix version of 8.4 (currently > 8.4.8) to see if the fix was back-patched. It works for me too in 8.4.recent; but I believe the relevant fix is in 8.4.5, which makes me doubt the OP's report of his server version. http://git.postgresql.org/gitweb/?p=3Dpostgresql.git&a=3Dcommitdiff&h=3Dd= c9cc887b7 4bfa0d40829c4df66dead509fdd8f6 regards, tom lane