Re: BUG #11207: empty path will segfault jsonb #>

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #11207: empty path will segfault jsonb #>
Date: 2014-08-21 03:09:40
Message-ID: CAKFQuwaHaYa++8ztK57iJvT4xv4YKiDS4WpAezCPV0oafh+vpA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Aug 20, 2014 at 10:51 PM, Tom Lane-2 [via PostgreSQL] <
ml-node+s1045698n5815665h39(at)n5(dot)nabble(dot)com> wrote:

> Andrew Dunstan <[hidden email]
> <http://user/SendEmail.jtp?type=node&node=5815665&i=0>> writes:
> > On 08/20/2014 07:30 PM, Tom Lane wrote:
> >> 1. #> now returns the input object if the RHS array is empty;
>
> > So will
> > val #>> '{}'
> > now return a dequoted bare scalar string? I think that's where the OP
> > actually came into this.
>
> Hm ... as the patch stands, you get the same thing from either operator:
>
> regression=# select '"foo"'::json #> '{}';
> ?column?
> ----------
> "foo"
> (1 row)
>
> regression=# select '"foo"'::json #>> '{}';
> ?column?
> ----------
> "foo"
> (1 row)
>
> If you think the latter should be dequoted, we can probably make it so.
> I'm not entirely convinced that's right though: you could argue that
> dequoting is a function of the -> operator and we applied zero such
> operators. (I'm not wedded to that argument, just raising it as food
> for thought.) Comments?
>
>
​Examples of both json object/array and json​ scalar results from the
different operators may be worth considering.

It is not obvious that your statement:

"dequoting is a function of the -> operator"

is true if one is just looking at the documentation.

Did you maybe intend to say the "->>" operator (which is stated to return
text, not json)?

"Get JSON object field by key" (->)

vs.

"Get JSON object field as text" (->>)

http://www.postgresql.org/docs/9.4/interactive/functions-json.html

The first one should be more precise, maybe: "Get JSON object value, by
key, as json"; and probably add the "by key" to the ->> operator at the
same time for consistency (though to be honest the "by key" part seems
redundant).

The use of "field" here instead of "value" is also confusing (note I
changed it in my alternative). Do we have the same problem for value/field
as we did for key/name?

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-11207-empty-path-will-segfault-jsonb-tp5815469p5815667.html
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrew Dunstan 2014-08-21 03:15:42 Re: BUG #11207: empty path will segfault jsonb #>
Previous Message Tom Lane 2014-08-21 02:50:17 Re: BUG #11207: empty path will segfault jsonb #>