I have a json column named "Payload" with a complex json structure as below-
{
"Number": "",
"Status": "",
"Parties": [
{
"BeCode": "SHANGMAG",
"PartyCode": "CNSHANGMAGVDR",
},
{
"BeCode": "FREEMAN",
"PartyCode": "CNFREEMANVDR",
}
],
"ContactName": "test",
"Type": "",
"Legs": [
{
"Name": "",
"ELocation": {
"City": "Enns",
"State": null,
"Country": "Austria",
},
"Socation": {
"City": "Buenos Aires",
"State": null,
"Country": "Argentina",
},
"Transport": 1
},
{
"Name": "84nbt",
"ELocation": {
"City": "Linz",
"State": null,
"Country": "Austria",
},
"SLocation": {
"City": "Enns",
"State": null,
"Country": "Austria",
},
"Transport": 2
}
]
"Bookings": [
{
"BookingNo": "",
"Status": "",
"Id": ""
}
]
}
Now I need to query all the rows where SLocation is equal to ELocation.
I was able to get the "Legs" part row vise using following query -
select payload->'Legs'
from public.shipping_instruction
However, If I dig deep into the json to get the SLocation and ELocation, the query doesnt exceute.
I am looking for something like the one below-
select payload->'Legs'
from public.shipping_instruction where
payload->'Legs'->'ELocation'->'City' =
payload->'Legs'->'SLocation'->'City'
But then here the Legs have multiple SLocation and ELocation how do I handle it?