Re: Wrong behaviour of array comparison when arrays contain nulls

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Lukas Eder <lukas(dot)eder(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Wrong behaviour of array comparison when arrays contain nulls
Date: 2022-04-06 13:37:52
Message-ID: 3034594.1649252272@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Lukas Eder <lukas(dot)eder(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

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