Re: Wrong behaviour of array comparison when arrays contain nulls

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Lukas Eder <lukas.eder@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2022-04-06T13:37:52Z
Lists: pgsql-bugs
Lukas Eder <lukas.eder@gmail.com> writes:
> For the following query:
> SELECT array[1, NULL] = array[1, NULL]
> H2 returns NULL whereas PostgreSQL returns TRUE. In my opinion and
> intuition, as well as according to ISO/IEC 9075-2:2016(E) 8.2 <comparison
> predicate> GR 1) b) ii), H2 is right and PostgreSQL is wrong.

If we don't impose a total order on array values, then we cannot build
btree indexes on such columns.  So yes, this is a deviation from the
SQL standard, and no we are not going to change it.

As for documentation, section 9.19 says

    The comparison operators compare the array contents
    element-by-element, using the default B-tree comparison function for
    the element data type, and sort based on the first difference.

which implies this behavior but perhaps could be more explicit.

			regards, tom lane