开发者

PostgreSQL - Insert all weekend dates from year xxxx to year yyyy

开发者 https://www.devze.com 2023-03-18 18:50 出处:网络
I have already built a holidays table containing all public holidays from 2000 to 2050. But I have should have put also all weekend dates and now I am trying to find an approach to it. Ca开发者_如何转

I have already built a holidays table containing all public holidays from 2000 to 2050. But I have should have put also all weekend dates and now I am trying to find an approach to it. Ca开发者_如何转开发n somebody suggest something? I checked and there are functions for calculating the number of the business days, but I need insertion of all weekends between these two years.


If 8.4+:

select 
    a::date as Sunday, 
    a::date - 1 as Saturday
from generate_series('2000-01-02'::date, '2050-12-31', '7 days') s(a)
;

Else:

select 
    '2000-01-02'::date + s.a as Sunday, 
    '2000-01-02'::date + s.a - 1 as Saturday
from generate_series(0, '2050-12-31'::date - '2000-01-02'::date, 7) s(a)
;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号