I am trying to do a join between 2 jsonb array in 2 different tables. The id to link them are inside the arrays.
This is what I have tried, I created a function on postgres that return me a list of Id (from table B) and I am trying to match them to Table A.
TableA
ID | resultA
1 | {records:[{id: 1, key: A, value: High}, {id: 2, key: B, value:Low}]}
TableB
ID | resultB
2 | {records:[{key: A, value: New Equipment}, {key: B, value: Old Equipment}]
So I got the SQL to show me 2 columns for both the Ids
select elem-> 'key' as TableA_id from TableA, lateral jsonb_array_elements(resultA -> 'records') elem
where elem-> 'key' in (public.myfunction('999'))
I am facing the following error: set-returning functions are not allowed in WHERE
Not sure what is wrong here.
in ( select * from myfunction(..) )- a_horse_with_no_name