I have JSON and I'm sending it to postgresql function. I need to insert every object inside weekDays array in a separate row and every key inside the object in a separate column and it needs to include weekId.
{
"weekId":20,
"weekDays":[
{
"day_of_week":"Monday",
"working_hours":22.5,
"description":"text",
"date":"May 22, 2019"
},
{
"day_of_week":"Tuesday",
"working_hours":22.5,
"description":"text",
"date":"May 22, 2019"
}
]
}
So what is the best way to do this? I can do something like this:
INSERT INTO timesheet(day_of_week, working_hours, description, date)
SELECT day_of_week, working_hours, description, date
FROM json_to_recordset(weeks_days)
AS x(day_of_week varchar, working_hours REAL, description text, date timestamp);
But how to include weekId that is not in array?
