我有一组函数查询,通常使用union来执行,如:
SELECT * FROM schedule_visit('2019-01-01')
UNION
SELECT * FROM schedule_visit('2019-01-02')
UNION
SELECT * FROM schedule_visit('2019-01-03')
...
如何在Postgres中循环执行从('2019-01-01')到('2019-12-31')的示例功能。
答案 0 :(得分:1)
如果参数可以按系列生成:
select f.*
from generate_series('2019-01-01'::timestamp, '2019-01-31', '1 day') as g(d)
cross join schedule_visit(d::date) as f
否则:
select f.*
from (
values
('2019-01-01'),
('2019-01-03'),
('2019-01-06'),
('2019-01-15')
) as v(d)
cross join schedule_visit(d::date) as f