pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Plettenbacher, Tobias (LWF) <Tobias.Plettenbacher@lwf.bayern.de>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: Bug or strange result of Max() on arrays containing NULL values
Date: Sat, 24 Aug 2024 10:54:48 -0400
Message-ID: <2411054.1724511288@sss.pgh.pa.us> (raw)
In-Reply-To: <325d78c062e945ebb286091f0eaa8b72@lwf.bayern.de>
References: <325d78c062e945ebb286091f0eaa8b72@lwf.bayern.de>

"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





view thread (3+ messages)  latest in thread

Message-ID: <2411054.1724511288@sss.pgh.pa.us>
Permalink:  ../2411054.1724511288@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2411054.1724511288@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Tobias.Plettenbacher@lwf.bayern.de, pgsql-bugs@lists.postgresql.org
  Subject: Re: Bug or strange result of Max() on arrays containing NULL values
  In-Reply-To: <2411054.1724511288@sss.pgh.pa.us>

* 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