Re: Aggregation results with json(b)_agg and array_agg in a SELECT with OUTER JOIN

David G. Johnston <david.g.johnston@gmail.com>

From: "David G. Johnston" <david.g.johnston@gmail.com>
To: sulfinu@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2023-05-19T20:14:07Z
Lists: pgsql-bugs
On Fri, May 19, 2023 at 9:59 AM <sulfinu@gmail.com> wrote:

> I've adjusted the statements so that you can clearly see that *there is a
> difference* between a missing outer-joined entity and its columns being
> actually set to NULL:
> Therefore, *it is a bug*.
>

Yep, the output of a left join, so far as the implicit composite (row?)
type produced for the nullable relation is concerned, has a form that
depends on whether or not a match was found.  i.e., the system produces
null::b for a non-match.  Its a reasonable way to express "no match
present".  And in the presence of an aggregate checking for {NULL} versus
{(,)} to differentiate the two cases is actually doable (see NULLIF())

A bug is "something that isn't working as designed" but you haven't said
what design you are taking to be authoritative.  Different queries and data
producing different outputs is something that usually is beneficial.

David J.