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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Peter Geoghegan <pg(at)heroku(dot)com>, justin(dot)vanwinkle(at)gmail(dot)com, pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #11207: empty path will segfault jsonb #>
Date: 2014-08-20 20:57:01
Message-ID: 5738.1408568221@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> On 08/20/2014 03:06 PM, Tom Lane wrote:
>> Peter Geoghegan <pg(at)heroku(dot)com> writes:
>>> Andrew argued it was
>>> preferable to stick to the historic behavior of json operators. IMV,
>>> we should have both operators return NULL. They should be consistent,
>>> which implies changing the behavior of the existing json variants too,
>>> but I don't think that's a big problem.

>> None of these operators existed before 9.3, so I don't put a lot of stock
>> in the idea that their corner-case behaviors should be considered
>> sacrosanct already. But that will become the case pretty soon; if we
>> don't get it right in 9.4 it will arguably be too late.

> I'm not terribly dogmatic about it. If the consensus is to change it
> then let's do it.

Well, if the preference is to make jsonb conform to the historical
behavior of json, we have work to do anyway. I noted this inconsistency
while drawing up some test cases:

regression=# SELECT '42'::json #> array['f2'];
?column?
----------

(1 row)

regression=# SELECT '42'::jsonb #> array['f2'];
ERROR: cannot extract path from a scalar

In this particular case the json code is self-inconsistent, since ->
throws an error:

regression=# SELECT '42'::json -> 'f2';
ERROR: cannot extract element from a scalar
regression=# SELECT '42'::jsonb -> 'f2';
ERROR: cannot call jsonb_object_field (jsonb -> text) on a scalar

I think returning NULL is the right thing here, really. Aside from being
arguably more convenient for indexing, we will get less push-back if we
make some operators go from throwing errors to returning null than if
we make some other operators go the other way.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2014-08-20 23:30:16 Re: BUG #11207: empty path will segfault jsonb #>
Previous Message Andrew Dunstan 2014-08-20 19:57:08 Re: BUG #11207: empty path will segfault jsonb #>