Re: Bug or strange result of Max() on arrays containing NULL values - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Bug or strange result of Max() on arrays containing NULL values
Date
Msg-id 2411054.1724511288@sss.pgh.pa.us
Whole thread Raw
In response to Bug or strange result of Max() on arrays containing NULL values  ("Plettenbacher, Tobias (LWF)" <Tobias.Plettenbacher@lwf.bayern.de>)
List pgsql-bugs
"Plettenbacher, Tobias (LWF)" <Tobias.Plettenbacher@lwf.bayern.de> writes:
> With Max(ARRAY[]) I get a strange result (in this case {NULL,7}):
> SELECT Max(ARRAY[Val, ID]) FROM (VALUES (1, 5), (2, 6), (NULL, 7)) AS T(Val, ID);

This is the expected result, because

=# select array[null, 7] > array[2, 6];
 ?column?
----------
 t
(1 row)

When comparing array elements (or members of any container type),
we treat two nulls as equal and a null as larger than any non-null.
You might think that such a comparison should yield null, but if
we did that then the comparisons would fail to provide a total
order for the container type.  That would, among other things,
break the ability to build b-tree indexes on such types.

            regards, tom lane



pgsql-bugs by date:

Previous
From: "Plettenbacher, Tobias (LWF)"
Date:
Subject: Bug or strange result of Max() on arrays containing NULL values
Next
From: "David G. Johnston"
Date:
Subject: Re: Bug or strange result of Max() on arrays containing NULL values