Re: Wrong behaviour of array comparison when arrays contain nulls - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Wrong behaviour of array comparison when arrays contain nulls
Date
Msg-id 3034594.1649252272@sss.pgh.pa.us
Whole thread Raw
In response to Wrong behaviour of array comparison when arrays contain nulls  (Lukas Eder <lukas.eder@gmail.com>)
List 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



pgsql-bugs by date:

Previous
From: Lukas Eder
Date:
Subject: Re: Wrong behaviour of array comparison when arrays contain nulls
Next
From: "hirose.masay-01@fujitsu.com"
Date:
Subject: RE: BUG #17421: Core dump in ECPGdo() when calling PostgreSQL API from 32-bit client for RHEL8