I have a simple JSON array:
_bb jsonb =
[
{
"so": "1",
"mdl": "Testing",
"pos": "Top"
},
{
"so": "1",
"mdl": "FlashSale",
"pos": "Bottom"
},
{
"so": "1",
"mdl": "Testing",
"pos": "Top"
}
]
What I want to achieve:
[
{
"so": "1",
"mdl": "Testing",
"pos": "Top"
},
{
"so": "1",
"mdl": "Testing",
"pos": "Top"
},
{
"so": "1",
"mdl": "FlashSale",
"pos": "Bottom"
}
]
I tried doing
Select _bb into _test ORDER BY _bb->>'pos' ASC ;
What I achieve is all the pos = "Top" be the first in the JSON and all the "Bottom" to be last. Is there a way to achieve this in Postgres?
ORDER BY _bb->>'pos' ASCwould help to change the array index - can you share the structure?.. also in your original jsonb,_bb[1]is equal to_bb[3]- right?.. so what you say you have achieved is what you want then - no?