Convert JSON to table type
2019-10-23
The function json_populate_record
can be used to cast a JSON object to a table type:
CREATE TABLE foo(bar int);
SELECT *
FROM json_populate_record(NULL::foo, '{"bar": 42}')
+-------+
| bar |
|-------|
| 42 |
+-------+
This can also be used to insert into the table:
INSERT INTO foo
SELECT *
FROM json_populate_record(NULL::foo, '{"bar": 42}')