Re: json accessors

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Hannu Krosing <hannu(at)krosing(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: json accessors
Date: 2012-11-30 15:29:47
Message-ID: 50B8D0EB.3000508@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2012-11-30 15:36:06 Re: [PATCH] Patch to fix a crash of psql
Previous Message Markus Wanner 2012-11-30 15:22:32 Re: Review: Extra Daemons / bgworker