Re: JSON for PG 9.2

Andrew Dunstan <andrew@dunslane.net>

From: Andrew Dunstan <andrew@dunslane.net>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: Josh Berkus <josh@agliodbs.com>, pgsql-hackers@postgresql.org
Date: 2012-01-31T20:15:42Z
Lists: pgsql-hackers

On 01/31/2012 02:49 PM, Merlin Moncure wrote:
> The major hole in functionality I see for heavy json users is the 
> reverse; how do you get json back into the database? With xml, at 
> least you could (ab)use xpath for that...with json you have to rely on 
> add-on support and/or ad hoc string parsing (that is, unless I'm 
> missing something -- I just noted Robert's commit of the JSON type). 
> since we can do: select array_to_json(array(select foo from foo)); it 
> seems natural to be able to want do do something like: WITH foos AS 
> (SELECT a_json_var::foo[] AS f) ( INSERT INTO foo SELECT (f).* FROM 
> foos ); Of course, you'd have to have non-anonymous (that is, defined 
> with CREATE TYPE AS) types defined to receive all the data, but that's 
> not so bad. Also, could xxx_to_json be hypothetically executed via 
> casts? e.g. select array(select foo from foo)::json;

At some stage there will possibly be some json-processing (as opposed to 
json-producing) functions, but not in 9.2 - it's too late for that. 
Until then there is PLV8: see 
<http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html> 
for example. Or someone could write an extension.

cheers

andrew