CREATE OR REPLACE FUNCTION food600.dobehniprepocet(
	xr integer DEFAULT 0)
    RETURNS void
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
DECLARE prik character varying(1000);
	zaznam integer;
	mxl_done integer;
BEGIN
--INSERT INTO food600.test (cas,text) values (clock_timestamp(),'3U XR'||(xr::bpchar));
mxl_done := 10000;
WHILE (mxl_done>0) LOOP
	SELECT prikaz, idriadok INTO prik, zaznam FROM food600.prikazy_prepocet WHERE riadok=xr ORDER BY idriadok LIMIT 1;
	IF prik ISNULL THEN
		mxl_done:=0;
	ELSE
--INSERT INTO food600.test (cas,text) values (clock_timestamp(),'3U XR'||(xr::bpchar)||','||(zaznam::bpchar));
		EXECUTE prik;
		DELETE FROM food600.prikazy_prepocet WHERE idriadok=zaznam;
--		update food600.prikazy_prepocet set riadok=-riadok  WHERE idriadok=zaznam;
END IF;
END LOOP;
END
$BODY$;
