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

Re: json api WIP patch

From: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
To: David Fetter <david(at)fetter(dot)org>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, 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 21:34:38
Message-ID: 50F5CB6E.9070400@archidevsys.co.nz (view raw or flat)
Thread:
Lists: pgsql-hackers
On 16/01/13 08:04, David Fetter wrote:
> On Mon, Jan 14, 2013 at 07:52:56PM -0500, Andrew Dunstan wrote:
>> 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.
> Perhaps we could compromise by making arrays 0.5-based.
>
> Cheers,
> David.
I think that is far to rational, perhaps the reciprocal of the golden 
ratio(0.618033...) would be more appropriate?

I used to be insistent that arrays should start with 1, now I find 
starting at 0 far more natural - because evrytime you start an array at 
1, the computer has to subtract 1 in order to calculate the entry.  Also 
both Java & C are zero based.

I first learnt FORTRAN IV which is 1 based, had a shock when I was 
learning Algol and found it was 0 based - many moons ago...


Cheers,
Gavin

In response to

pgsql-hackers by date

Next:From: Magnus HaganderDate: 2013-01-15 21:35:36
Subject: Re: BUG #7809: Running pg_dump on slave w/ streaming replication fails if there are unlogged tables
Previous:From: Tom LaneDate: 2013-01-15 21:26:18
Subject: Re: unlogged tables vs. GIST

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