79134485

Date: 2024-10-28 17:30:36
Score: 0.5
Natty:
Report link
SELECT 
  sku,
  jsonb_object_agg(warehouse_name, (warehouse_data->>'stock')::int) AS warehouses,
  additional_info
FROM (
  SELECT 
    sku,
    warehouse_name,
    warehouse_data,
    additional_info
  FROM 
    products,
    jsonb_each(warehouses) AS warehouse(warehouse_name, warehouse_data)
) AS expanded
GROUP BY sku

Reading the documentation, I found the answer with the function of jsonb_each, which gives me the key and the value from the column of warehouse.

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Dan Cruz