CREATE OR REPLACE FUNCTION food600.dokoncprepocet(
	midriadok integer)
    RETURNS void
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE 
AS $BODY$
DECLARE prik character varying(1000);
	mxl_done integer;
BEGIN
mxl_done := 10000;
WHILE (mxl_done>0) LOOP
	SELECT prikaz INTO prik FROM food600.prikazy_prepocet WHERE idriadok=midriadok ORDER BY idriadok LIMIT 1;
	IF prik ISNULL THEN
		mxl_done:=0;
	ELSE
		EXECUTE prik;
		DELETE FROM food600.prikazy_prepocet WHERE idriadok=midriadok;
		mxl_done:=0;
END IF;
END LOOP;
END
$BODY$;
