pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David G Johnston <david.g.johnston@gmail.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #11178: JSONB : The NOT operator applies to the <@ operator, even after casting to ::bool
Date: Mon, 18 Aug 2014 06:55:06 -0700 (PDT)
Message-ID: <1408370106705-5815230.post@n5.nabble.com> (raw)
In-Reply-To: <1408369143374-5815229.post@n5.nabble.com>
References: <20140815211138.2543.16364@wrigleys.postgresql.org>
	<1408147143170-5815058.post@n5.nabble.com>
	<1408369143374-5815229.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Christian Pronovost wrote
> 
> David G Johnston wrote
>> The presence of "NOT" does not (aside from a possible bug) change the
>> "<@" operator into the "@>" operator.
> I was wrong assuming the inversion of the "<@" operator.

As Tom noted you were correct in your observation but you were observing a
bug...see below, and Tom's comments regarding "operator negator functions",
for the knowledge I was missing when I replied the first time.


>> "NOT" simply inverts the supplied boolean value.
> This does not seem to be the case. In the following example, the same
> query returns false whether there is a NOT operator or not. 
> 
> SELECT (testcolumn->'ID' <@ '["2"]') FROM "TestJsonb" --Returns false (as
> expected)
> SELECT NOT(testcolumn->'ID' <@ '["2"]') FROM "TestJsonb" --Returns false (
*
> not as expected
*
> )
> 
> To be noted that outside of the context of a table, this works fine:
> 
> SELECT ('"1"'::jsonb <@ '["2"]') --Returns false (as expected)
> SELECT NOT('"1"'::jsonb <@ '["2"]') --Returns true (as expected)
> 
> I am confused

Apparently "NOT()" is both an operator itself (which acts on a boolean) and
is also an optimization mechanic (which acts on an operator).  Since the
non-table version does not require any optimization the function behavior is
taken and the correct answer is returned.  In a table context - *even when
the expression is not in a WHERE clause apparently* ... - the optimization
code checks to see whether the associated operator has an associated negator
function and then, if present, tries to compare a direct equality using the
matched negator function.  Since jsonb incorrectly had just such an
operator, which indeed caused PostgreSQL to attempt to match equality using
the "@>" operator, the behavior you saw was manifested.

I feel I am missing something in the above conclusion but it is what comes
to mind why I try to explain what you are showing here.

Furthermore, I am still confused why your example:

NOT((... @< ...)::text)::bool 

failed to fail...the cast to text should blow things up since the NOT
shouldn't be able to cross the casting boundary to see the operator for
optimization...

David J.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-11178-JSONB-The-NOT-operator-applies-to-the-operator-eve...
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (7+ messages)  latest in thread

Message-ID: <1408370106705-5815230.post@n5.nabble.com>
Permalink:  ../1408370106705-5815230.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1408370106705-5815230.post@n5.nabble.com

 · 

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-bugs@postgresql.org
  Cc: david.g.johnston@gmail.com
  Subject: Re: BUG #11178: JSONB : The NOT operator applies to the <@ operator, even after casting to ::bool
  In-Reply-To: <1408370106705-5815230.post@n5.nabble.com>
  References: <20140815211138.2543.16364@wrigleys.postgresql.org> <1408147143170-5815058.post@n5.nabble.com> <1408369143374-5815229.post@n5.nabble.com> <1408370106705-5815230.post@n5.nabble.com>

* 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