pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: != ANY(array) does not behave as expected
Date: Fri, 7 Dec 2018 13:48:45 +0100
Message-ID: <ba26cd81-487e-71f3-86ae-22dedd08b577@gmx.net> (raw)
In-Reply-To: <BCCA73C2165E8947A2E786EC482564DE013DB9A7A6@CCPMAILDAG03.cantab.local>
References: <BCCA73C2165E8947A2E786EC482564DE013DB9A7A6@CCPMAILDAG03.cantab.local>

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





view thread (5+ messages)  latest in thread

Message-ID: <ba26cd81-487e-71f3-86ae-22dedd08b577@gmx.net>
Permalink:  ../ba26cd81-487e-71f3-86ae-22dedd08b577@gmx.net/
Also on:    postgresql.org/message-id/ba26cd81-487e-71f3-86ae-22dedd08b577@gmx.net

 · 

reply

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: spam_eater@gmx.net
  Subject: Re: != ANY(array) does not behave as expected
  In-Reply-To: <ba26cd81-487e-71f3-86ae-22dedd08b577@gmx.net>
  References: <BCCA73C2165E8947A2E786EC482564DE013DB9A7A6@CCPMAILDAG03.cantab.local> <ba26cd81-487e-71f3-86ae-22dedd08b577@gmx.net>

* 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