Postgresql 如何返回周数+年数+星期五周数

Postgresql 如何返回周数+年数+星期五周数,postgresql,Postgresql,在sql中,它如下所示: select to_char(d,'WW') as Week , to_char(d,'YYYY') as Year , to_char(d,'DD') as "Day of Friday" , d from ( select (level-1)*7 + to_date('02/01/2015','DD/MM/YYYY') d from dual connect by level <

在sql中,它如下所示:

select to_char(d,'WW')    as Week
     , to_char(d,'YYYY')  as Year
     , to_char(d,'DD')    as "Day of Friday"
     , d
from (
      select (level-1)*7 + to_date('02/01/2015','DD/MM/YYYY') d
        from dual
      connect by level <= 53*5);

但是我需要一个Postgres脚本…

你一年前试过吗?看看

Postgres的日期时间掩码几乎是一样的。在你的情况下,我想他们是平等的:

select to_char(d,'WW')    as Week
     , to_char(d,'YYYY')  as Year
     , to_char(d,'DD')    as "Day of Friday"
     , d
from to_date('02/01/2015','DD/MM/YYYY') d
给出:

01;2015;12;2015-01-12


除非本周不是第一天,周五也不是一个月的某一天……

谢谢您的回复

这就是我想要的:

SELECT 
     extract('week' from d) as "Week"
    ,extract('year' from d) as "Year"
    ,extract('day' from d)  as "Friday Number"
FROM generate_series('2015-01-02'::date, '2015-12-31'::date, '1 week'::interval) d

您需要编写脚本的所有内容都在中。