DROP PROCEDURE IF EXISTS rds.sp_cleanfrllorecipeprocess;

--CREATE OR REPLACE PROCEDURE rds.sp_cleanfrllorecipeprocess(
--    "ExportId" uuid,
--    "All" boolean
--)
--    LANGUAGE plpgsql
--AS
--$$
--DECLARE
--    p_exportid uuid := "ExportId";
--    v_num      int  := 1000;
--BEGIN
    
--    CREATE TEMP TABLE tmp_obj
--    (
--        id  uuid NOT NULL UNIQUE,
--        num serial
--    );
    
--    INSERT INTO tmp_obj
--    SELECT DISTINCT exportfrllorecipedataid
--    FROM rds.t_export_frllo_recipe_data fed
--    WHERE fed.exportfrllorecipe = p_exportid;
    
--    LOOP
--        IF
--            NOT EXISTS (SELECT 1 FROM tmp_obj LIMIT 1)
--        THEN
--            EXIT;
--        END IF;
--        UPDATE rds.t_export_frllo_recipe_data fed
--        SET frlloid     = NULL,
--            frllostatus = case when "All" = '0' then frllostatus else NULL end,
--            frlloerror  = case when "All" = '0' then frlloerror else NULL end,
--            regnum = NULL
--        WHERE EXISTS(SELECT 1 FROM tmp_obj t WHERE t.id = exportfrllorecipedataid AND t.num <= v_num)
--          AND exportfrllorecipe = p_exportid;
        
--        DELETE FROM tmp_obj WHERE num <= v_num;
--        v_num := v_num + 1000;
--    END LOOP;


--END;
--$$
