I'm wondering if there's a way to append array to a specific index/position in an jsonb array in Postgresql 9.6?
Let's imagine that my code below is my json:
{
"date": "2018-02-12",
"author": "devoplex",
"block": [
{ "color": "#C70039", "title": "Fruit" },
{ "color": "#DAF7A6", "title": "Vegetable" },
{ "color": "#DAF7A6", "title": "Meat" }
]
}
I want to append this object in my "block" array:
{ "color": "#581845", "title": "Candy" }
But I want this object to become the third index/position without replacing anything. So finally I can have this result:
{
"date": "2018-02-12",
"author": "devoplex",
"block": [
{ "color": "#C70039", "title": "Fruit" }, <---- Initial line
{ "color": "#DAF7A6", "title": "Vegetable" }, <---- Initial line
{ "color": "#581845", "title": "Candy" }, <---- New line
{ "color": "#DAF7A6", "title": "Meat" } <---- Initial line
]
}
This example in not my actual code but it's the same issue. This is for the construction of a form, so it need to be in a specific order or else it won't make any sense. Thanks you.