Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XKAJD-0001ML-5N for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Aug 2014 18:08:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XKAJB-0006Ig-JU for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Aug 2014 18:08:29 +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 1XKAJA-0006IZ-If for pgsql-bugs@postgresql.org; Wed, 20 Aug 2014 18:08:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XKAJ2-0004Bd-KW for pgsql-bugs@postgresql.org; Wed, 20 Aug 2014 18:08:26 +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 s7KI8Hoo027010; Wed, 20 Aug 2014 14:08:17 -0400 From: Tom Lane To: justin.vanwinkle@gmail.com, Andrew Dunstan cc: pgsql-bugs@postgresql.org Subject: Re: BUG #11207: empty path will segfault jsonb #> In-reply-to: <26461.1408497576@sss.pgh.pa.us> References: <20140818195634.2543.56277@wrigleys.postgresql.org> <22294.1408487132@sss.pgh.pa.us> <26461.1408497576@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 19 Aug 2014 21:19:36 -0400" Date: Wed, 20 Aug 2014 14:08:17 -0400 Message-ID: <27009.1408558097@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 I wrote: > Surely #> with a K-element path ought to act the same as K invocations > of the -> operator ... and zero invocations would result in just having > the original input object, no? Poking at that some more ... regression=# select '{"a": {"b":{"c": "foo"}}}'::json #> '{a}'; ?column? -------------------- {"b":{"c": "foo"}} (1 row) regression=# select '{"a": {"b":{"c": "foo"}}}'::json #> '{a,b}'; ?column? -------------- {"c": "foo"} (1 row) regression=# select '{"a": {"b":{"c": "foo"}}}'::json #> '{a,b,c}'; ?column? ---------- "foo" (1 row) regression=# select '{"a": {"b":{"c": "foo"}}}'::json #> '{a,b,c,d}'; ?column? ---------- (1 row) That comports with successive applications of -> up to the last step, where you'd get an error instead of NULL: regression=# select '"foo"'::json -> 'd'; ERROR: cannot extract element from a scalar Is there a reason for these to behave inconsistently, and if not, which behavior should we standardize on? Considering that you get NULL not an error for extracting a nonexistent element from an object, I think there is some case to be made for saying that returning NULL is the more convenient behavior. Of course one can also argue for wanting this operator to throw errors if the JSON structure doesn't match the operation, but it seems like we've chosen to prefer being lax. 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