From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Chris Wilson <chris.wilson@cantabcapital.com>
Cc: pgsql-general\@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: != ANY(array) does not behave as expected
Date: Fri, 07 Dec 2018 18:49:53 +0000
Message-ID: <87o99x2ne0.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <BCCA73C2165E8947A2E786EC482564DE013DB9A7A6@CCPMAILDAG03.cantab.local>
References: <BCCA73C2165E8947A2E786EC482564DE013DB9A7A6@CCPMAILDAG03.cantab.local>
>>>>> "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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: andrew@tao11.riddles.org.uk, chris.wilson@cantabcapital.com
Subject: Re: != ANY(array) does not behave as expected
In-Reply-To: <87o99x2ne0.fsf@news-spur.riddles.org.uk>
References: <BCCA73C2165E8947A2E786EC482564DE013DB9A7A6@CCPMAILDAG03.cantab.local> <87o99x2ne0.fsf@news-spur.riddles.org.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox