Re: Further issues with jsonb semantics, documentation

From: Peter Geoghegan <pg(at)heroku(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Further issues with jsonb semantics, documentation
Date: 2015-06-04 05:55:36
Message-ID: CAM3SWZSfnbHnbjrcQp9udaHv2fTEtPm91pN7zWk=bQs5qnFmDw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jun 3, 2015 at 7:02 PM, Peter Geoghegan <pg(at)heroku(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2015-06-04 06:42:26 Re: 9.4.1 -> 9.4.2 problem: could not access status of transaction 1
Previous Message Amit Kapila 2015-06-04 04:44:52 Re: Re: [COMMITTERS] pgsql: Map basebackup tablespaces using a tablespace_map file