Re: PATCH: Add hstore_to_json() - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: PATCH: Add hstore_to_json()
Date
Msg-id 4B2BD042.4090908@dunslane.net
Whole thread Raw
In response to Re: PATCH: Add hstore_to_json()  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: PATCH: Add hstore_to_json()  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers

Robert Haas wrote:
> On Fri, Dec 18, 2009 at 11:32 AM, David E. Wheeler <david@kineticode.com> wrote:
>   
>> On Dec 18, 2009, at 4:49 AM, Peter Eisentraut wrote:
>>
>>     
>>> Should we create a json type before adding all kinds of json formatted
>>> data?  Or are we content with json as text?
>>>       
>> json_data_type++
>>     
>
> What would that do for us?
>
> I'm not opposed to it, but it seems like the more important thing
> would be to provide functions or operators that can do things like
> extract an array, extract a hash key, identify whether something is a
> hash, list, or scalar, etc.
>
>
>   

In principle it's not a bad idea to have a JSON type for several 
reasons. First, it's a better match than hstore for serializing an 
arbitrary tuple, because unlike hstore it can have nested arrays and 
composites, just as tuples can. Second, it might well be very useful if 
we could easily return results as JSON to AJAX applications, which are 
increasingly becoming the norm. And similarly we might be able to reduce 
application load if Postgres could perform operations on JSON, rather 
than having to return it all to the client to process.

I think it would be useful if someone produced a JSON module as, say, a 
pgFoundry project, to start with, and we would then be better able to 
assess its usefulness. An interesting question would be how one might 
sanely index such things.

You're correct that we don't necessarily need a new type, we could just 
make it text and have a bunch of operations, but that seems to violate 
the principle of data type abstraction a bit. If the operations can be 
sure that the object is valid JSON they could skip a bunch of sanity 
checks that they would otherwise need to do if just handed an arbitrary 
piece of text.

cheers

andrew





pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: question about implementing XA-ish functions
Next
From: Greg Smith
Date:
Subject: Re: Closing out CommitFest 2009-11