pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: ab@principiamentis.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16022: to_json on arrays with unusual lower bound is not intuitive
Date: Wed, 25 Sep 2019 10:34:16 -0400
Message-ID: <23022.1569422056@sss.pgh.pa.us> (raw)
In-Reply-To: <16022-5c864f8a572d5b5b@postgresql.org>
References: <16022-5c864f8a572d5b5b@postgresql.org>

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





view thread (3+ messages)  latest in thread

Message-ID: <23022.1569422056@sss.pgh.pa.us>
Permalink:  ../23022.1569422056@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23022.1569422056@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ab@principiamentis.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16022: to_json on arrays with unusual lower bound is not intuitive
  In-Reply-To: <23022.1569422056@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox