Re: != ANY(array) does not behave as expected - Mailing list pgsql-general

From Andrew Gierth
Subject Re: != ANY(array) does not behave as expected
Date
Msg-id 87o99x2ne0.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to != ANY(array) does not behave as expected  (Chris Wilson <chris.wilson@cantabcapital.com>)
List pgsql-general
>>>>> "Chris" == Chris Wilson <chris.wilson@cantabcapital.com> writes:

 Chris> However, if we try to invert it by using the != operator, then
 Chris> we get unexpected results:

Mr. De Morgan would like a word.
https://en.wikipedia.org/wiki/De_Morgan%27s_laws

In short, if you have a condition of the form (a OR b) and you want to
negate it, then you find that:

    NOT (a OR b)  is equivalent to  (NOT a) AND (NOT b)

Since  x = ANY (array[1,2])  is equivalent to (x = 1) OR (x = 2), then
the negation would be (x != 1) AND (x != 2), not OR.

Which can be conveniently expressed as  x != ALL (array[1,2]).

So just as you interchange AND and OR when inverting the sense of a
condition, you also interchange ALL and ANY for exactly the same
reasons.

 Chris> expression NOT IN (subquery)

https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_NOT_IN

 Chris> And is it a bug that one can't use unnest in a NOT IN expression
 Chris> in the WHERE clause?

No.

-- 
Andrew (irc:RhodiumToad)


pgsql-general by date:

Previous
From: Ken Tanzer
Date:
Subject: Re: != ANY(array) does not behave as expected
Next
From: Adrian Klaver
Date:
Subject: Re: Importing tab delimited text file using phpPgAdmin 5.1 GUI