I have a table in my database that returns me some columns. One of them is a list of JSONs that are, in fact, other tables, but in JSON format. The image belows show an example.
I want to transform each row of that column "data" into separate tables, because I need specific information inside each JSON. How can I do that using only PostgreSQL?
You can use below query to create transfer your data (json data column) into a new table
insert into json_table
SELECT p.*
from test_json t
cross join lateral json_populate_record (NULL::json_table, t.data ::json) as p;
Here json_table is the new table in which data will be stored, test_json is your table in which json data is stored in data column. Replace those with your table names and you are good to go.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.