Re: Further issues with jsonb semantics, documentation - Mailing list pgsql-hackers

From Peter Geoghegan
Subject Re: Further issues with jsonb semantics, documentation
Date
Msg-id CAM3SWZSfnbHnbjrcQp9udaHv2fTEtPm91pN7zWk=bQs5qnFmDw@mail.gmail.com
Whole thread Raw
In response to Further issues with jsonb semantics, documentation  (Peter Geoghegan <pg@heroku.com>)
List pgsql-hackers
On Wed, Jun 3, 2015 at 7:02 PM, Peter Geoghegan <pg@heroku.com> wrote:
> Consider this case:
>
> postgres=# select '{"c":5, "a":6, "b":7}'::jsonb - 1;
>      ?column?
> ------------------
>  {"a": 6, "c": 5}
> (1 row)
>
> Clearly anyone expecting the value "a" to be removed here would be in
> for a surprise. Moreover, it is inconsistent with the established
> behavior of the corresponding array-wise subscript operator:
>
> postgres=# select '{"c":5, "a":6, "b":7}'::jsonb -> 1;
>  ?column?
> ----------
>  [null]
> (1 row)

For similar reasons, I think that this inconsistency is unacceptable:

postgres=# select '["a", "b", "c"]'::jsonb - -1; ?column?
------------["a", "b"]
(1 row)

postgres=# select '["a", "b", "c"]'::jsonb -> -1;?column?
----------[null]
(1 row)

jsonb now supports Python-style negative subscripting to index
backward. I think that this a fine idea. However, I also think it's a
big POLA violation that this was not done for the ordinary array
subscripting operator ("operator jsonb -> integer") at the same time
as "operator jsonb - integer" was added. Although doing this will
require a compatibility note in the 9.5 release notes, it's extremely
unlikely to destabilize anybody's app, and makes a lot of sense.
-- 
Peter Geoghegan



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Re: [COMMITTERS] pgsql: Map basebackup tablespaces using a tablespace_map file
Next
From: Noah Misch
Date:
Subject: Re: [GENERAL] 9.4.1 -> 9.4.2 problem: could not access status of transaction 1