Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iD8N7-0001IX-00 for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Sep 2019 14:34:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iD8N5-0007XT-Sb for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Sep 2019 14:34:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iD8N5-0007XM-LH for pgsql-bugs@lists.postgresql.org; Wed, 25 Sep 2019 14:34:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iD8N2-00057z-Qs for pgsql-bugs@lists.postgresql.org; Wed, 25 Sep 2019 14:34:23 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8PEYGuM023023; Wed, 25 Sep 2019 10:34:16 -0400 From: Tom Lane 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 In-reply-to: <16022-5c864f8a572d5b5b@postgresql.org> References: <16022-5c864f8a572d5b5b@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 25 Sep 2019 12:23:11 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23021.1569422056.1@sss.pgh.pa.us> Date: Wed, 25 Sep 2019 10:34:16 -0400 Message-ID: <23022.1569422056@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form 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