On 02/10/2013 05:43 AM, Yeb Havinga wrote:
> On 2013-02-08 15:15, Andrew Dunstan wrote:
>>
>>
>>
>> Revised patch attached. The problem also existed with the
>> get*_as_text functions (and their operators). Some additional
>> regression tests are added to test these cases.
>
> Hi,
>
> I did some minor things with the patch today.
>
> 1. thanks for the work on the json type, great to see it in Postgres
> and also more functions on it!
>
> 2.
> during compile on
>
> jsonfuncs.c: In function `each_object_field_end':
> jsonfuncs.c:1151:13: warning: assignment makes integer from pointer
> without a cast
Thanks, I have fixed this in my code, and it will be included in the
next patch I post.
>
>
>
> 3. I was wondering how to access the first author from this json snippet:
>
> {
> "id": "QZr82w_eSi8C",
> "etag": "KZ+JsrkCdqw",
> "volumeInfo": {
> "title": "Heads Up Software Construction",
> "authors": [
> "Dan Malone",
> "Dave Riles"
> ],
>
>
> and played a bit with json_get_path_as_text(document, 'volumeInfo',
> 'authors') that accepts a list of keys as arguments. Have you thought
> about an implementation that would accept a single path argument like
> 'volumeInfo.authors[0]' ? This might be more powerful and easy to use,
> since the user does not need to call another function to get the first
> element from the author array, and the function call does not need to
> be changed when path lenghts change.
try:
json_get_path_as_text(document, 'volumeInfo', 'authors', '0')
There are other ways to spell this, too:
json_get_path_as_text(document, variadic '{volumeInfo,authors,0}'::text[])
or
document->>'{volumeInfo,authors,0}'::text[]
I'm actually wondering if we should use different operator names for the
get_path*op functions so we wouldn't need to type qualify the path
argument. Maybe ?> and ?>> although I'm reluctant to use ? in an
operator given the recent JDBC discussion. Or perhaps #> and #>>.
cheers
andrew