Re: BUG #16022: to_json on arrays with unusual lower bound is not intuitive

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ab(at)principiamentis(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16022: to_json on arrays with unusual lower bound is not intuitive
Date: 2019-09-25 14:34:16
Message-ID: 23022.1569422056@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-docs

PG Bug reporting form <noreply(at)postgresql(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2019-09-25 20:09:30 Re: BUG #16020: ICU Collations querys
Previous Message PG Bug reporting form 2019-09-25 12:23:11 BUG #16022: to_json on arrays with unusual lower bound is not intuitive

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2019-09-25 14:43:19 Logical replication restriction documentation
Previous Message PG Bug reporting form 2019-09-25 12:23:11 BUG #16022: to_json on arrays with unusual lower bound is not intuitive