Good Morning,
I receive the following JSON-Format via PostgREST:
{
"timestamp": "2022-02-04T09:55:21+00:00",
"uses": [
{
"id": 3,
"name": "Name1",
"capacity": 300,
"usage": 0,
"available": 300
},
{
"id": 4,
"name": "Name2",
"capacity": 450,
"usage": 120,
"available": 330
},
{
"id": 5,
"name": "Name3",
"capacity": 50,
"usage": 11,
"available": 39
}
]
}
I would like to write a function in PostgreSQL that automatically writes the data from the nested array into a table.
Example:
INSERT INTO tblLogs (timestamp, id, capacity, usage, available) VALUES("2022-02-04T09:55:21+00:00", 3, 300, 0, 300)
INSERT INTO tblLogs (timestamp, id, capacity, usage, available) VALUES("2022-02-04T09:55:21+00:00", 4, 450, 120, 330)
...
I don't know how i map the attribute "timestamp" to each item of the nested array.
Please help, i'm a Postgres-Newbie :)