Re: JSON manipulation functions - Mailing list pgsql-hackers

From Tom Lane
Subject Re: JSON manipulation functions
Date
Msg-id 20885.1273864195@sss.pgh.pa.us
Whole thread Raw
In response to Re: JSON manipulation functions  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: JSON manipulation functions
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Thu, May 13, 2010 at 9:47 PM, Joseph Adams
> <joeyadams3.14159@gmail.com> wrote:
>> [] retrieves a value of a JSON array/object by (one-based) index. �In
>> other words, value[n] is equivalent to selecting the nth row of
>> json_values(value) (provided value is of type JSON). �Examples:
>> 
>> SELECT ('[1,2,3,4]'::JSON)[3]
>> -- Result is '3'::JSON
>> 
>> SELECT ('{"a": 1, "b": 2, "c": 3, "d": 4}'::JSON)[3]
>> -- Result is '3'::JSON

> I think some kind of array deference and object deference mechanism is
> absolutely, positively 100% required.  I don't know whether the
> particular syntax you've proposed here is best or whether we should
> pick another syntax or just use function notation, but I think we
> definitely need *something*.

Trying to use array notation on something that isn't a SQL array type
is guaranteed to be a mess.  I strongly recommend that you not attempt
that.  Just define a function for it.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Kenneth Marshall
Date:
Subject: Re: Generating Lots of PKs with nextval(): A Feature Proposal
Next
From: "Marc G. Fournier"
Date:
Subject: Re: List traffic