All we need is an easy explanation of the problem, so here it is.
I have two jsonb columns(keys,values).
Eg: keys colum value =
values column =
I want to write a select query to get the output as below based on the array index.
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
You need to unnest the arrays then aggregate everything back into a single JSON value:
select x.value from the_table t cross join lateral ( select jsonb_object_agg(k.ky, v.value) as value from jsonb_array_elements_text(t.keys) with ordinality as k(ky,idx) join jsonb_array_elements(t.values) with ordinality as v(value,idx) on k.idx = v.idx ) x
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂