Here is my data sample of my jsonb field itineraries in a row of my table trips:
[
{
"nights": 10,
"destinations": [
"Cronaside",
"New Emory",
"East Mattiechester"
],
"departure_date_end": "2020-09-21",
"return_date_latest": "2020-10-01",
"departure_date_start": "2020-09-14"
},
{
"nights": 10,
"destinations": [
"Port Verdie",
"Chaunceymouth",
"Isabellemouth"
],
"departure_date_end": "2020-10-08",
"return_date_latest": "2020-10-18",
"departure_date_start": "2020-09-14"
}
]
My aim is to return rows from trips ordered by the earliest departure_date_start of this jsonb field itineraries. Here is my simple attempt:
SELECT *
from trips
ORDER BY itineraries->>'departure_date_start' ASC
However, because itineraries is an array and can have multiple departure_date_start values, does Postgres handle this automatically? Or am I required to loop over the array?
Using Postgres 9.6