I want to select the last value from an array nested like this:
{ tier: [
{ tier: [] },
{ tier: [] },
{ tier: [
{ tier: 1},
{ tier: 2},
{ tier: 3}, // < this item
]
},
]
}
I've tried to use something like this from other examples, but the syntax is eluding me. I either get a 'column does not exist' or 'cannot extract elements from object'
SELECT *,
t0->tier->(jsonb_array_length(t0->tier) - 1) t1,
t1->tier->(jsonb_array_length(t1->tier) - 1) t2,
t2->tier->(jsonb_array_length(t2->tier) - 1) t3,
FROM data t0