create_supply_every_stock.sql 519 B

123456789101112131415161718192021
  1. CREATE OR REPLACE FUNCTION supply_every_stock(amount INTEGER) RETURNS void AS
  2. $$
  3. DECLARE
  4. stoCursor CURSOR IS SELECT sto_quantity FROM Stock FOR UPDATE;
  5. stoQuantity Stock.sto_quantity%TYPE;
  6. BEGIN
  7. RAISE NOTICE 'Iterate on existing stocks only';
  8. -- Iterate on storage
  9. OPEN stoCursor;
  10. LOOP
  11. FETCH stoCursor INTO stoQuantity;
  12. EXIT WHEN stoQuantity IS NULL;
  13. RAISE NOTICE 'Supply %', amount;
  14. END LOOP;
  15. CLOSE stoCursor;
  16. RAISE NOTICE 'End';
  17. END;
  18. $$
  19. LANGUAGE plpgsql;