Good job! Functions are powerful because they allow you to reuse existing code when writing new functions.
In this section, we'll look at various ways you can use and reuse query results in functions and how you can invoke functions within each other in PL/pgSQL.
CREATE FUNCTION create_shipment(customer_id integer, prod_id integer, quantity integer)
RETURNS void AS $$
WHERE customer_id = cust_id;
stock_quantity := get_stock_quantity(prod_id);
IF (stock_quantity < quantity)
RAISE EXCEPTION 'Not enough product in stock %', prod_id;
PERFORM add_shipment(prod_id, quantity, customer_id, shipment_address, contact_number);
$$ LANGUAGE plpgsql;
This example shows various ways of calling complex statements in a function. In this section, we'll look in detail at the syntax of complex statements in PostgreSQL and PL/pgSQL.