Re: BUG #9519: Allows storing scalar json, but fails when querying

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #9519: Allows storing scalar json, but fails when querying
Date: 2014-03-10 21:14:16
Message-ID: 1394486056457-5795451.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-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-tp5795417p5795451.html
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeff Janes 2014-03-10 21:42:59 Re: BUG #9519: Allows storing scalar json, but fails when querying
Previous Message David Johnston 2014-03-10 21:09:02 Re: BUG #9519: Allows storing scalar json, but fails when querying