0

I'm trying to import some tables into a PostgreSQL db that have been stored as json files. Example data:

[{
"token": "a978f9793a594d11860e9cf7962996d7",
"name": "vehicle.moving",
"description": "Vehicle is moving."
},
{
"token": "95e38bf08c2842f39f2d64ba8152b265",
"name": "vehicle.stopped",
"description": "Vehicle, with a driver/rider in/on it, is currently stationary but has an intent to move."
}]

Would like the result to look like:

token                            | name            | description
---------------------------------+-----------------+--------------------
a978f9793a594d11860e9cf7962996d7 | vehicle.moving  | Vehicle is moving.
95e38bf08c2842f39f2d64ba8152b265 | vehicle.stopped | Vehicle, with a driver/rider in/on it, is currently stationary but has an intent to move.

My SQL currently looks like this:

\set content `type "F:\Datasets\attribute.json"`
insert into attribute select * from jsonb_array_elements(:'content');

Which just adds rows of quoted json to my table. Have been bashing at this all day (SQL rookie) and would be very grateful for help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.