Re: Bypassing NULL elements in row_to_json function - Mailing list pgsql-general

From David G. Johnston
Subject Re: Bypassing NULL elements in row_to_json function
Date
Msg-id CAKFQuwbz-Rm=gxx5_s94H13yNohyPmUa2KVf3k5-3oKQUL1sBA@mail.gmail.com
Whole thread Raw
In response to Re: Bypassing NULL elements in row_to_json function  (Michael Nolan <htfoot@gmail.com>)
Responses Re: Bypassing NULL elements in row_to_json function
List pgsql-general
On Sat, Apr 9, 2016 at 9:48 PM, Michael Nolan <htfoot@gmail.com> wrote:

2nd Followup:  It turns out that loading a table from a JSON string is more complicated than going from a table to JSON, perhaps for good reason.  There does not appear to be a direct inverse to the row_to_json() function, but it wasn't difficult for me to write a PHP program that takes the JSON file I created the other day and converts it back to a series of inserts, recreating the original table. 

Of course this simple program does NO validation (not that this file needed any), so if the JSON string is not well-formed for any of a number of reasons, or if it is not properly mapped to the table into which the inserts are made, an insert could fail or result in incorrect data. 
--
Mike Nolan


​json_populate_record(base anyelement, from_json json)
json_populate_recordset(base anyelement, from_json json)

Exists in 9.3 too...though if you are going heavy json I'd suggest doing whatever you can to keep up with the recent releases.

David J.

pgsql-general by date:

Previous
From: Durumdara
Date:
Subject: Re: Really unique session ID - PID + connection timestamp?
Next
From: Venkata Balaji N
Date:
Subject: Re: Shipping big WAL archives to hot standby