Skip to content

RETURN

CREATE OR REPLACE FUNCTION getStock(p_id INT)
RETURNS INT AS $$
DECLARE
stock INT;
BEGIN
SELECT product_stock INTO stock FROM product WHERE product_id = p_id;
RETURN stock;
END; $$
LANGUAGE plpgsql;
Terminal window
CREATE FUNCTION

The given function getStock takes p_id as an input parameter. It queries the product table with p_id and returns the product_stock. It is written using procedural language PostgreSQL PL/pgSQL. The output CREATE FUNCTION states that function was created successfully.