Skip site navigation (1) Skip section navigation (2)

Re: json api WIP patch

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: json api WIP patch
Date: 2013-01-15 00:52:56
Message-ID: 50F4A868.2080303@dunslane.net (view raw or flat)
Thread:
Lists: pgsql-hackers
On 01/14/2013 07:36 PM, Merlin Moncure wrote:
> While testing this I noticed that integer based 'get' routines are
> zero based -- was this intentional?  Virtually all other aspects of
> SQL are 1 based:
>
> postgres=# select json_get('[1,2,3]', 1);
>   json_get
> ----------
>   2
> (1 row)
>
> postgres=# select json_get('[1,2,3]', 0);
>   json_get
> ----------
>   1
> (1 row)
>


Yes. it's intentional. SQL arrays might be 1-based by default, but 
JavaScript arrays are not. JsonPath and similar gadgets treat the arrays 
as zero-based. I suspect the Json-using community would not thank us for 
being overly SQL-centric on this - and I say that as someone who has 
always thought zero based arrays were a major design mistake, 
responsible for countless off-by-one errors.

cheers

andrew


In response to

Responses

pgsql-hackers by date

Next:From: Andres FreundDate: 2013-01-15 01:38:45
Subject: logical changeset generation v4
Previous:From: Merlin MoncureDate: 2013-01-15 00:36:00
Subject: Re: json api WIP patch

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group