Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XIRPR-0001ZN-MY for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Aug 2014 23:59:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XIRPQ-0001QV-IC for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Aug 2014 23:59:48 +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 1XIRPP-0001QO-HX for pgsql-bugs@postgresql.org; Fri, 15 Aug 2014 23:59:47 +0000 Received: from 216-139-250-139.aus.us.siteprotect.com ([216.139.250.139] helo=joe.nabble.com) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XIRPM-0005Qv-D9 for pgsql-bugs@postgresql.org; Fri, 15 Aug 2014 23:59:45 +0000 Received: from sam.nabble.com ([192.168.236.26]) by joe.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1XIROw-0005Vn-6H for pgsql-bugs@postgresql.org; Fri, 15 Aug 2014 16:59:18 -0700 Date: Fri, 15 Aug 2014 16:59:03 -0700 (PDT) From: David G Johnston To: pgsql-bugs@postgresql.org Message-ID: <1408147143170-5815058.post@n5.nabble.com> In-Reply-To: <20140815211138.2543.16364@wrigleys.postgresql.org> References: <20140815211138.2543.16364@wrigleys.postgresql.org> 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: 1.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 cpronovost wrote > The following bug has been logged on the website: > > Bug reference: 11178 > Logged by: Christian Pronovost > Email address: > cpronovost@ > PostgreSQL version: 9.4beta2 > Operating system: Windows 7 Pro SP1 > Description: > > When using the <@ operator in conjunction with the NOT operator on a jsonb > column, the NOT reverse the <@ operator(becomes a @>). > > However, when casting the result of the <@ operation to a ::bool, the NOT > operator stills applies to the <@ operator, rather than the ::bool. The presence of "NOT" does not (aside from a possible bug) change the "<@" operator into the "@>" operator. "NOT" simply inverts the supplied boolean value so that "not(true) := false" and vice-versa. Mutually exclusive json values will result in false being returned no matter which operator is used. > Note: the NOT operator will apply to the ::bool if it is casted to ::text > prior to ::bool.(See complete example below) > > Is the ::bool cast ignored since the operation already returns a boolean? > (causing the NOT operator to apply to the jsonb <@ Operator instead?) The cast is likely ignored if the input is already of the desired type - but it shouldn't matter either way. And as noted below casting the bool to a text and applying the NOT should fail - not serve as a workaround... > CREATE TABLE "TestJsonb" > ( > testcolumn jsonb > ) > WITH ( > OIDS=FALSE > ); > ALTER TABLE "TestJsonb" > OWNER TO postgres; > > INSERT INTO "TestJsonb" VALUES ('{"ID":"1"}') > > SELECT testcolumn->'ID' <@ '["1"]' FROM "TestJsonb" --Returns true (as > expected) > SELECT NOT(testcolumn->'ID' <@ '["1"]') FROM "TestJsonb" --Returns false > (as > expected) > > SELECT testcolumn->'ID' <@ '["2"]' FROM"TestJsonb" --Returns false (as > expected) > SELECT NOT((testcolumn->'ID' <@ '["2"]')::bool) FROM "TestJsonb" --Returns > false (not as expected, seems to change the '<@' operator to '@>') > > SELECT NOT((testcolumn->'ID' <@ '["2"]')::text)::bool FROM "TestJsonb" > --Returns true (as expected) I cannot test it myself but you are correct that the behavior of the NOT((...<@...)::bool) is wrong; though confusingly so... In the last scenario I am also confused why it actually evaluates in the first place. SELECT NOT('false'::text); emits an error in 9.3.4 (argument of NOT must be type boolean, not type text) 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-tp5815056p5815058.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