Re: BUG #16022: to_json on arrays with unusual lower bound is not intuitive - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #16022: to_json on arrays with unusual lower bound is not intuitive
Date
Msg-id 23022.1569422056@sss.pgh.pa.us
Whole thread Raw
In response to BUG #16022: to_json on arrays with unusual lower bound is not intuitive  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> I would expect the array indices of a JSON array to match with the
> subscripts of a postgres array when converting them back and forth.
> However, Postgres lets the JSON array begin at the `lower_bound` of the
> array, not at subscript 1 (= index 0).
> For example, `to_json('[-2:5]={-2,-1,0,1,2,3,4,5}'::int[])` results in
> `[-2,-1,0,1,2,3,4,5]` where I would have expected `[1,2,3,4,5]` (or an
> error, since JSON arrays must not have negative indices).

I can see no reason whatever for either of those definitions to be
better than the established one.  If you want some other conversion
rule, write your own function that behaves the way you want.

            regards, tom lane



pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #16022: to_json on arrays with unusual lower bound is not intuitive
Next
From: Peter Eisentraut
Date:
Subject: Re: BUG #16020: ICU Collations querys