Giving the following JSONB data structure of a stopInfo column in a myTable table:
{
"stopInfo": [
{
"stopType": "Origin",
"partnerId": "KR01",
"locationId": "KR57",
"partnerName": "Seller"
},
{
"stopType": "Destination",
"partnerId": "225735",
"locationId": "0301223684",
"partnerName": "Buyer"
}
]
}
How do I write a single select statement to get the partnerName of the Origin stop and the Destination stop?
This is as close as I've come.
select (jsonbColumn->'stopInfo'->>'partnerName') as OriginPartner,
(jsonbColumn->'stopInfo'->>'partnerName') as DestinationPartner
from myTable;
Clearly there's some kind of in-line criteria I need to apply for each column to ensure I'm getting the value out of the right array element, but I'm struggling to find a good example of this simple scenario.