I have the following table.
CREATE TEMPORARY TABLE temp_detail
(
purchase_order_detail_id INTEGER,
item_id integer,
qty numeric(18,2),
project_id integer,
category_id integer,
supplier_id integer,
rate numeric(18,2)
);
I am getting the grouped result with ids using
SELECT array_agg(purchase_order_detail_id), project_id, category_id, supplier_id
FROM temp_detail
GROUP BY project_id, category_id, supplier_id
Now I want to insert project_id, category_id, supplier_id into a master table and item_id,qty,rate into its detail table. Detail table will have the master table id as foreign key. Please help.
Assuming this schema:
This will do it: