Usa json_agg() e jsonb_array_elements() funzioni:
select json_agg(cell)
from (
select jsonb_array_elements(elem->'cell') cell
from (
select jsonb_array_elements(data->'cust') elem
from product_cust
) subsub
) sub
Puoi unire due sottoquery interne:
select json_agg(cell)
from (
select jsonb_array_elements(jsonb_array_elements(data->'cust')->'cell') cell
from product_cust
) sub
Raggruppa i risultati per productid:
select productid, json_agg(cell)
from (
select productid, jsonb_array_elements(jsonb_array_elements(data->'cust')->'cell') cell
from product_cust
) sub
group by 1
order by 1