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

From Thomas Kellerer
Subject Re: != ANY(array) does not behave as expected
Date
Msg-id a56a738e-ce00-2e0d-f346-6c969f30836d@gmx.net
Whole thread Raw
In response to Re: != ANY(array) does not behave as expected  (Thomas Kellerer <spam_eater@gmx.net>)
Responses Re: != ANY(array) does not behave as expected  (Ken Tanzer <ken.tanzer@gmail.com>)
List pgsql-general
Thomas Kellerer schrieb am 07.12.2018 um 13:48:
> Chris Wilson schrieb am 07.12.2018 um 13:39:
>> However, if we try to invert it by using the != operator, then we get unexpected results:
>>
>> select * from foo where id NOT IN (1, 2); /* returns row 3 only, as expected */
>> select * from foo where id != ANY (ARRAY[1, 2]); /* returns all rows, unexpected */
> 
> id <> ANY (...) means: return "true" if at least one of the elements is not equal to the value on the left side. 
> 
> What you are looking for is the ALL operator
> 
>   select * 
>   from foo 
>   where id <> ALL (ARRAY[1, 2]); 
> 
> That is essentially the equivalent to NOT IN

See here for a longer explanation:

   https://stackoverflow.com/a/10675636




pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: != ANY(array) does not behave as expected
Next
From: Arthur Zakirov
Date:
Subject: Re: psql profiles?