I am currently learning PostgreSQL and have hit a wall when it comes to stored procedures.
I have an order table with these columns:
OrderId
OrderStatus
OrderTime
I also have an order line table
OrderId
OrderLineId
OrderLineAmount
OrderLineCost
I am trying to write a stored procedure which would create an order and then insert a list of order lines into the second table.
Here is what I have so far:
CREATE OR REPLACE FUNCTION public.createcustomerorder(
_orderstatus integer,
_ordertimestamp timestamp)
RETURNS int4 AS
$BODY$
DECLARE
last_id int4;
BEGIN
INSERT INTO "Order"
(orderstatus, ordertimestamp)
VALUES(_orderstatus, _ordertimestamp)
RETURNING orderid INTO last_id;
RETURN last_id;
END;
$BODY$
LANGUAGE plpgsql;
I am finding it difficult for figure out how I can pass in the parameters, and then how to do the actual insert.
Thanks for your time