Re: BUG #16425: Possible error in full join

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: c_michal(at)poczta(dot)onet(dot)pl, pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16425: Possible error in full join
Date: 2020-05-08 16:17:41
Message-ID: CAMkU=1w3yX9FynqnYyS-c=SZ3-NwB7=qXMFEkC6RrLKUovd8Og@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, May 8, 2020 at 11:37 AM PG Bug reporting form <
noreply(at)postgresql(dot)org> wrote:

> The following bug has been logged on the website:
>
> Bug reference: 16425
> Logged by: Michal C
> Email address: c_michal(at)poczta(dot)onet(dot)pl
> PostgreSQL version: 12.2
> Operating system: Windows 10
> Description:
>
> Sorry for my English
> My PG version: "PostgreSQL 12.2, compiled by Visual C++ build 1914,
> 64-bit"
>
> Example for bag:
> with d (a,b) as (values (null::varchar(255),1))
> select *
> from d d1
> full join d d2 using (a,b);
>
> Result:
> "a" "b"
> null 1
> null 1
>
> Why select returns 2 records, Is this correct?
>
>
This looks correct to me. It returns one row from the left side and one
from the right side. The way NULL comparisons work, the two rows are not
known to be equal and so are not merged. The USING uses equality for
testing.

To get one row, you could rewrite it explicitly using ON and replacing one
equality with IS NOT DISTINCT FROM, like this:

with d (a,b) as (values (NULL::varchar(255),1))
select *
from d d1
full join d d2 on(d1.b=d2.b and d1.a is not distinct from d2.a);

Cheers,

Jeff

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Thusitha Maheepala 2020-05-09 02:33:47 Postgredb issue
Previous Message PG Bug reporting form 2020-05-08 15:25:54 BUG #16425: Possible error in full join