Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WN7Wh-0004Cm-4J for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Mar 2014 21:14:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WN7Wg-0004kn-E9 for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Mar 2014 21:14:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WN7Wf-0004kg-GO for pgsql-bugs@postgresql.org; Mon, 10 Mar 2014 21:14:21 +0000 Received: from sam.nabble.com ([216.139.236.26]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WN7Wc-0007rU-6j for pgsql-bugs@postgresql.org; Mon, 10 Mar 2014 21:14:20 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1WN7Wa-0002zf-Ev for pgsql-bugs@postgresql.org; Mon, 10 Mar 2014 14:14:16 -0700 Date: Mon, 10 Mar 2014 14:14:16 -0700 (PDT) From: David Johnston To: pgsql-bugs@postgresql.org Message-ID: <1394486056457-5795451.post@n5.nabble.com> In-Reply-To: <531E2977.7060002@hogranch.com> References: <20140310150952.398.53642@wrigleys.postgresql.org> <531E17E1.9020009@joh.to> <531E2977.7060002@hogranch.com> Subject: Re: BUG #9519: Allows storing scalar json, but fails when querying MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 John R Pierce wrote > On 3/10/2014 1:39 PM, Alf Kristian St=C3=B8yle wrote: >> This is the "unfortunate" part: >> /select data->>'foo' from jtest; >> =3D> ERROR: cannot extract element from a scalar >> / >> So either, only accept JSON object (not simple JSON values), or make=20 >> the JSON query operators work with JSON values as well. >=20 > the json ->> 'fieldname' operator has no meaning when applied to a=20 > scalar value. what would you suggest it should do? return a NULL ? "key does not exist" is represented by NULL if the operator is applied to an object so, in theory, since the key does not exist in a scalar the same value - NULL - would not be unexpected. =46rom a theory perspective, and based upon typical database normalization rules, the current behavior makes the most sense but it does force the user to be consistent in defining of their JSON models - a little big-brother-ish but if you are only going to support a single set of rules the more-strict ones are generally preferable. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-9= 519-Allows-storing-scalar-json-but-fails-when-querying-tp5795417p5795451.ht= ml Sent from the PostgreSQL - bugs mailing list archive at Nabble.com. --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs