I have a postgres
query, which works fine when I run it as a query. However, I would like to convert it to pl/r
and be able to dynamically input the start and end date.
The SQL that works is:
with date as (
select d as first_day,
d + interval '1 month' - interval '1 day' as last_day
from generate_series('2010-01-01'::date,
'2018-12-01'::date,
'1 month') as d
) select last_day::date as snapshot_date from date;
Would like to make a pl/r like:
DROP FUNCTION IF EXISTS standard.seq_monthly(min_date_str char, max_date_str char);
CREATE FUNCTION standard.seq_monthly(min_date_str char, max_date_str char)
RETURNS setof dates AS
$$
with date as (
select d as first_day,
d + interval '1 month' - interval '1 day' as last_day
from generate_series(min_date_str::date,
max_date_str::date,
'1 month') as d
) select last_day::date as snapshot_date from date;
$$
LANGUAGE 'plr';
select * from standard.seq_monthly('2010-01-01' , '2018-12-01')
However, I am getting error while running the function. The error is
R parse error caught in "PLR711818 <- function(min_date_str,max_date_str)
Have tried declaring the max min date to be date as well.
Any help is highly appreciated.