On Fri, May 14, 2010 at 10:35 PM, Joseph Adams <joeyadams3.14...@gmail.com> wrote: > By the way, I'm considering making it so JSON arrays will be treated > like objects when it comes to -> and the json_keys function. Thus, > json_keys('[1,4,9,16,25]') would yield '{1,2,3,4,5}', and > ('[1,4,9,16,25]'::JSON) -> 3 would yield the third item. This would > obviate the need for an array-only subscript function/operator. > > In general, I prefer zero-based counting, but because PostgreSQL's > array indexing is one-based, one-based array keys would be better for > the sake of consistency. Note that if there was a function like this > in the future: > > -- Access a JSON object like you would in JavaScript > json_path('{"squares": [1,4,9,16,25]}', '.squares[2]') > > There could be confusion, as JavaScript uses zero-based indexing.
I think you should take Tom's suggestion and use functional notation rather than operator notation. And then I think you should use 0-based counting to match JS. But I'm game to be outvoted if others disagree. Basically, I think you're right: it will be confusing to have two different notations, and we're certainly going to want a JS equivalent of XPath at some point. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers