I'm trying to create materialized views inside stored function, which has date range as inbound parameters.
CREATE OR REPLACE FUNCTION public.create_view_for_reporting(
prev_date timestamp without time zone,
curr_date timestamp without time zone)
RETURNS void AS
$BODY$
BEGIN
DROP MATERIALIZED VIEW public.messages_prev_day;
CREATE MATERIALIZED VIEW public.messages_prev_day AS
SELECT * FROM messages
WHERE messages.date >= prev_date AND messages.date < curr_date
WITH NO DATA;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
Function created with no issues, though when I run it:
select * from public.create_view_for_reporting ('2017-05-08','2017-05-09')
it is failing with error
ERROR: materialized views may not be defined using bound parameters
So, I'm wondering if there's any possible variant to create materialized view with parameters?