Re: json accessors - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: json accessors
Date
Msg-id 50B8D0EB.3000508@dunslane.net
Whole thread Raw
In response to Re: json accessors  (Hannu Krosing <hannu@2ndQuadrant.com>)
Responses Re: json accessors  (Hannu Krosing <hannu@2ndQuadrant.com>)
List pgsql-hackers
On 11/30/2012 10:04 AM, Hannu Krosing wrote:
>>
>>
>> OK, so based on this discussion, I'm thinking of the following:
>>
>>  * keep the original functions and operators. json_keys is still
>>    required for the case where the json is not flat.
>>  * json_each(json) => setof (text, text)
>>    errors if the json is not a flat object
>
> Why not json_each(json) => setof (text, json) ? with no erroring out ?
>
> if the json does represent text it is easy to convert to text on the 
> query side.


Well, it would be possible, sure. I'm not sure how useful. Or we could 
do both fairly easily. It's not as simple or efficient as you might 
think to dequote / de-escape json string values, which is why the 
original API had variants for returning both types of values. Maybe we 
need a function for doing just that.

>
>>  * json_unnest(json) => setof json
>>    errors if the json is not an array
>>  * json_unnest_each => setof (int, text, text)
>>    errors if the array is not an array of flat objects
> json_unnest_each => setof (int, text, json)

ditto.

>>  * populate_record(record, json) => record
>>    errors if the json isn't a flat object
> errors if the values are not castable to records field types
>
> nb! some nonflatness is castable. especially to json or hstore or 
> record types


If the record has a json field, certainly. If it has a record field, 
fairly likely.  hstore could probably be a problem given it's not a core 
type. Similarly to the generation functions discussed in another thread, 
I could possibly look up a cast from json to the non-core type and use 
it. That might work for hstore.

I'll try to keep this as permissive as possible.

>
>>  * populate_recordset(record, json) => setof record
>>    errors if the json is not an array of flat objects
> ditto

ditto ;-)


cheers

andrew




pgsql-hackers by date:

Previous
From: Markus Wanner
Date:
Subject: Re: Review: Extra Daemons / bgworker
Next
From: Tom Lane
Date:
Subject: Re: [PATCH] Patch to fix a crash of psql