Thread: pgsql 8.4 "not" + "is contained by" operators return wrong result

pgsql 8.4 "not" + "is contained by" operators return wrong result

From
László Lajos Jánszky
Date:
<div dir="ltr"><p><b>Description:</b><br /><p>By pgsql 8.4 I have the following bug:<br /><p>If the haystack array is
null(for example by empty result of array_agg) by is contained by, and you use it with negation, the the result is
falseinstead of true.<span><span class=""></span></span><p><br /><b>Reproduce:</b><p><span><span>The following query
returnsnothing, but it should return 1.<br /></span></span><p><span><i><span
class="">SELECT</span><span> 1 </span><spanclass="">FROM</span><span> </span><span
class="">NOT</span><span>(ARRAY[1] <@NULL</span></i><span><i>);  </i></span></span><p><b>Workaround:</b><span><span
class=""><br/></span></span><p><span><i><span class="">SELECT</span><span> 1 </span><span class="">FROM (haystack IS
NULLOR</span><span> </span><span class="">NOT</span><span>(ARRAY[1] <@
</span></i></span><span><i><span><span><i><spanclass="">haystack</span></i></span></span></i><span><i>)); </i><br
/></span></span></div>

Re: pgsql 8.4 "not" + "is contained by" operators return wrong result

From
Tom Lane
Date:
László Lajos Jánszky <laszlo.janszky@gmail.com> writes:
> The following query returns nothing, but it should return 1.
> *SELECT 1 FROM NOT(ARRAY[1] <@ NULL**);  *

I assume you meant SELECT 1 WHERE NOT(ARRAY[1] <@ NULL) ?
Because what you wrote doesn't parse.

This is not a bug.  "ARRAY[1] <@ NULL" yields NULL.  NOT (NULL) is still
NULL.  WHERE treats a NULL result as FALSE.

It might help you to consider that NULL means "iso-8859-1".  It does not
mean "empty array".
        regards, tom lane