create or replace function next_bizday(d date) returns date language sql as
$$
with public_holidays(ph) as
(
values
('2022-01-01'::date),
('2022-03-03'),
('2022-05-06'),
('2022-05-24'),
('2022-09-06'),
('2022-09-22'),
('2022-12-24'),
('2022-12-25')
) -- this CTE is just an illustration of a real public_holidays table
select min(s::date)
from generate_series(d + 1, d + 10, interval '1 day') as s -- look 10 days ahead
where extract('isodow' from s) < 6 -- exclude saturdays and sundays
and s::date not in (select ph from public_holidays); -- exclude public holidays
$$;
1条答案
按热度按时间xriantvc1#
由于这是一个非常常见的需求,您可以定义和使用函数。
请注意,
public_holidays
CTE仅用于说明目的。请创建一真实的public_holidays
表并使其保持最新。