pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Johnston <polobo@yahoo.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #9519: Allows storing scalar json, but fails when querying
Date: Mon, 10 Mar 2014 14:14:16 -0700 (PDT)
Message-ID: <1394486056457-5795451.post@n5.nabble.com> (raw)
In-Reply-To: <531E2977.7060002@hogranch.com>
References: <20140310150952.398.53642@wrigleys.postgresql.org>
	<531E17E1.9020009@joh.to>
	<CA+tXr--Z7ap5mcaBVNKOi9NXd2MaZG9FO4t7cVj3cCMZjz+g6g@mail.gmail.com>
	<531E2977.7060002@hogranch.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

John R Pierce wrote
> On 3/10/2014 1:39 PM, Alf Kristian Støyle wrote:
>> This is the "unfortunate" part:
>> /select data->>'foo' from jtest;
>> => ERROR:  cannot extract element from a scalar
>> /
>> So either, only accept JSON object (not simple JSON values), or make 
>> the JSON query operators work with JSON values as well.
> 
> the json ->> 'fieldname' operator has no meaning when applied to a 
> 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.

From 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-9519-Allows-storing-scalar-json-but-fails-when-querying-...
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



view thread (14+ messages)  latest in thread

Message-ID: <1394486056457-5795451.post@n5.nabble.com>
Permalink:  ../1394486056457-5795451.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1394486056457-5795451.post@n5.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: polobo@yahoo.com
  Subject: Re: BUG #9519: Allows storing scalar json, but fails when querying
  In-Reply-To: <1394486056457-5795451.post@n5.nabble.com>
  References: <20140310150952.398.53642@wrigleys.postgresql.org> <531E17E1.9020009@joh.to> <CA+tXr--Z7ap5mcaBVNKOi9NXd2MaZG9FO4t7cVj3cCMZjz+g6g@mail.gmail.com> <531E2977.7060002@hogranch.com> <1394486056457-5795451.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox