pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: listar <listar@mail.ru>
To: pgsql-bugs@postgresql.org
Subject: BUG #6154: wrong result with nested left-joins
Date: Mon, 8 Aug 2011 13:13:33 GMT
Message-ID: <201108081313.p78DDX6W021751@wwwmaster.postgresql.org> (raw)


The following bug has been logged online:

Bug reference:      6154
Logged by:          listar
Email address:      listar@mail.ru
PostgreSQL version: 8.4.5
Operating system:   Linux 2.6.36-gentoo-r5
Description:        wrong result with nested left-joins
Details: 

It's hard to explain, but easy to show =)
here we are:

SELECT * FROM
(
                SELECT 1 as key1
) sub1
LEFT JOIN 
(
                SELECT sub3.key3, value2 FROM
                (
                               SELECT 1 as key3
                ) sub3
                LEFT JOIN 
                (
                               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=sub3.key3
)
sub2 ON sub1.key1 = sub2.key3

The result of this query:
key1;key3;value2
1;1;NULL

And this is the problem - value2 can't be NULL because of COALESCE in sub4
(at least I think that it can't be =))
Anyway if we'll change 
SELECT sub3.key3, sub4.value2 FROM
with
SELECT sub3.key3, value2 FROM
we will got correct result:
key1;key3;value2
1;1;1



view thread (11+ messages)  latest in thread

Message-ID: <201108081313.p78DDX6W021751@wwwmaster.postgresql.org>
Permalink:  ../201108081313.p78DDX6W021751@wwwmaster.postgresql.org/
Also on:    postgresql.org/message-id/201108081313.p78DDX6W021751@wwwmaster.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: listar@mail.ru
  Subject: Re: BUG #6154: wrong result with nested left-joins
  In-Reply-To: <201108081313.p78DDX6W021751@wwwmaster.postgresql.org>
  References: <201108081313.p78DDX6W021751@wwwmaster.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox