On Wed, Jun 3, 2015 at 7:02 PM, Peter Geoghegan <p...@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


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to