Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XKCwP-0002Em-MY for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Aug 2014 20:57:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XKCwP-0007pv-3M for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Aug 2014 20:57:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XKCwO-0007pn-GC for pgsql-bugs@postgresql.org; Wed, 20 Aug 2014 20:57:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XKCwK-000566-QI for pgsql-bugs@postgresql.org; Wed, 20 Aug 2014 20:57:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s7KKv1AW005739; Wed, 20 Aug 2014 16:57:01 -0400 From: Tom Lane To: Andrew Dunstan cc: Peter Geoghegan , justin.vanwinkle@gmail.com, pgsql-bugs Subject: Re: BUG #11207: empty path will segfault jsonb #> In-reply-to: <53F4FD94.4070201@dunslane.net> References: <20140818195634.2543.56277@wrigleys.postgresql.org> <22294.1408487132@sss.pgh.pa.us> <26461.1408497576@sss.pgh.pa.us> <27009.1408558097@sss.pgh.pa.us> <28104.1408561567@sss.pgh.pa.us> <53F4FD94.4070201@dunslane.net> Comments: In-reply-to Andrew Dunstan message dated "Wed, 20 Aug 2014 15:57:08 -0400" Date: Wed, 20 Aug 2014 16:57:01 -0400 Message-ID: <5738.1408568221@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) 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 Andrew Dunstan writes: > On 08/20/2014 03:06 PM, Tom Lane wrote: >> Peter Geoghegan writes: >>> Andrew argued it was >>> preferable to stick to the historic behavior of json operators. IMV, >>> we should have both operators return NULL. They should be consistent, >>> which implies changing the behavior of the existing json variants too, >>> but I don't think that's a big problem. >> None of these operators existed before 9.3, so I don't put a lot of stock >> in the idea that their corner-case behaviors should be considered >> sacrosanct already. But that will become the case pretty soon; if we >> don't get it right in 9.4 it will arguably be too late. > I'm not terribly dogmatic about it. If the consensus is to change it > then let's do it. Well, if the preference is to make jsonb conform to the historical behavior of json, we have work to do anyway. I noted this inconsistency while drawing up some test cases: regression=# SELECT '42'::json #> array['f2']; ?column? ---------- (1 row) regression=# SELECT '42'::jsonb #> array['f2']; ERROR: cannot extract path from a scalar In this particular case the json code is self-inconsistent, since -> throws an error: regression=# SELECT '42'::json -> 'f2'; ERROR: cannot extract element from a scalar regression=# SELECT '42'::jsonb -> 'f2'; ERROR: cannot call jsonb_object_field (jsonb -> text) on a scalar I think returning NULL is the right thing here, really. Aside from being arguably more convenient for indexing, we will get less push-back if we make some operators go from throwing errors to returning null than if we make some other operators go the other way. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs