Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XJNOy-0007FY-JJ for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Aug 2014 13:55:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XJNOx-0000kQ-VT for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Aug 2014 13:55:12 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XJNOw-0000jT-SP for pgsql-bugs@postgresql.org; Mon, 18 Aug 2014 13:55:11 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XJNOt-0004t8-BI for pgsql-bugs@postgresql.org; Mon, 18 Aug 2014 13:55:09 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1XJNOs-0006gd-Mx for pgsql-bugs@postgresql.org; Mon, 18 Aug 2014 06:55:06 -0700 Date: Mon, 18 Aug 2014 06:55:06 -0700 (PDT) From: David G Johnston To: pgsql-bugs@postgresql.org Message-ID: <1408370106705-5815230.post@n5.nabble.com> 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> Subject: Re: BUG #11178: JSONB : The NOT operator applies to the <@ operator, even after casting to ::bool MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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-even-after-casting-to-bool-tp5815056p5815230.html 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