Given:

CREATE TABLE jsontbl ( id int, label text, json_obj json);

I need the create two rows from the following JSON, with the json_obj in
each row equal to the text/json object in the content

1,'one',{"id":1,"label":"one"}
2,'two',{"id":2,"label":"two"}

I'd like to not have to hard-code the columns ...

I've dead-ended at:

SELECT jpr.*, json_src
FROM json_array_elements($json$[ { "id":1, "label":"one" }, { "id":2,
"label":"two" } ]$json$::json) jae (json_src),
LATERAL json_populate_record(null::jsontbl, json_src) jpr

Which gets me all of the content but I'm stumped at how to send this
through "INSERT INTO jsobtbl" without knowing the columns and without
removing the ".*"

Looking for inspiration here...

It would nice to simply have a function defined:

RETURNS TABLE (out_rec anyelement, src_json json)

I can easily live with the treatment of out_rec as a composite type.

Thanks!

David J.

Reply via email to