"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