Re: Best way to populate nested composite type from JSON` - Mailing list pgsql-general

From Merlin Moncure
Subject Re: Best way to populate nested composite type from JSON`
Date
Msg-id CAHyXU0ysrOa2qpEApfhDO_z0JRzcg-VnDd5tFS8eQqRfwNeF_w@mail.gmail.com
Whole thread Raw
In response to Best way to populate nested composite type from JSON`  (Chris Travers <chris.travers@gmail.com>)
Responses Re: Best way to populate nested composite type from JSON`  (Chris Travers <chris.travers@gmail.com>)
List pgsql-general
On Wed, Sep 11, 2013 at 11:55 PM, Chris Travers <chris.travers@gmail.com> wrote:
> Hi everyone;
>
> I have been starting to experiment with the JSON accessors in 9.3.  I
> immediately found that my preferred use, populating nested composite types,
> is not supported.  Also of course one cannot manipulate JSON nodes, which
> leads to the question of how best to do this.  I had some ideas:
>
> 1.  A custom C function utilizing the internal functions PostgreSQL offers
> for JSON parsing (probably looking at the json_populate_record() as a base)
>
> 2.  Utilizing hstore as an intermediate representation along with
> json_each()
>
> 3.  Perhaps using something like pl/perlu or the like.
>
> This leads to a few questions, including whether it would be worthwhile
> looking at trying to handle nested types in json_populate_record() and if
> anyone is working on such a thing currently.

Can we see a hypothetical example?  json best practices for me are to
use standard tables and than serialize/deserialize json as it goes
through the door and not use nested composite types in your actual
table definitions.  I think it should all fit if you do it right: you
json_[each/array_elements] the wrapping json then insert it into
un-nested actual tables.  If you must have a final destination as a
nested composite, I think at the worst case you might have to make
some transition composites...

merlin


pgsql-general by date:

Previous
From: rob stone
Date:
Subject: Re: Need help with Inet type
Next
From: Michael Paquier
Date:
Subject: Re: 9.2 Replication in Ubuntu ; need help