I would like to migrate this postgre function to mysql. The function receives two dates as a parameter and returns an array with the intermediate dates received.
example:
send two dates '2019-01-01' & '2019-05-31'.
i get: {'2019-01-01','2019-02-01','2019-03-01','2019-04-01','2019-05-01'}
The function postgre:
CREATE OR REPLACE FUNCTION schema.date_range(
start_date date,
end_date date)
RETURNS date[]
LANGUAGE 'plpgsql'
COST 100
VOLATILE
-- ROWS 0
AS $BODY$
DECLARE
date_exe date := start_date;
array_date date[];
BEGIN
WHILE date_exe <= end_date
LOOP
-- MAKE YOUR STUFF
RAISE NOTICE '%', date_exe;
array_date := array_append(array_date,date_exe);
date_exe := date_exe + interval '1 month';
END LOOP;
RETURN array_date;
END;
$BODY$;
The idea is to insert in a table the periods per month between two dates, with the range returned (from the postgre function) performed a for loop to insert these values:
SET array_date_range = schema.date_range( '2019-01-01', '2019-05-31'); -- function I want to migrate
for i in coalesce(array_lower(array_date_range, 1),1)..coalesce(array_upper((array_date_range, , 1),1) loop
SELECT LAST_DAY((array_date_range[i]) INTO v_date_end;
INSERT INTO schama.table (date_ini, date_end)
VALUES (array_date_range[i] ,v_date_end);
end loop;
thanks in advance