Skip to content
Advertisement

Convert a json which is a list of dictionaries into column/row format in Postgresql

I´ve a json which is a list of dictionaries with the next syntax:

The json is really big and each dictionary have different amount of key/values fields. And what I want to do is to create a table in postgresSQL where the key represents a column and the value a row. In the example explained above I would like table like this:

The only solution I can think is putting the values one by one but this is no efficient at all

Advertisement

Answer

You can use jsonb_to_recordset to create record set out of your json and then use insert into to insert the records.

Sample DBFiddle

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement