Re: PATCH: Add hstore_to_json()

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PATCH: Add hstore_to_json()
Date: 2009-12-18 18:56:02
Message-ID: 4B2BD042.4090908@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas wrote:
> On Fri, Dec 18, 2009 at 11:32 AM, David E. Wheeler <david(at)kineticode(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Smith 2009-12-18 19:18:18 Re: Closing out CommitFest 2009-11
Previous Message Heikki Linnakangas 2009-12-18 18:34:20 Re: question about implementing XA-ish functions