■ GENERATE_SERIES 함수 : 1개월치 날짜 구하기

------------------------------------------------------------------------------------------------------------------------

 

SELECT DATE_TRUNC('MONTH', CURRENT_DATE)::DATE + (I - 1)

FROM   GENERATE_SERIES

(

    1

   ,EXTRACT(DAY FROM DATE_TRUNC('MONTH', CURRENT_DATE + INTERVAL '1 MONTHS')::DATE - 1)::INTEGER

) AS T(I);

 

 

SELECT DATE_TRUNC('MONTH', CURRENT_DATE)::DATE + (I - 1)

FROM   GENERATE_SERIES

(

    1

   ,EXTRACT(DAY FROM DATE_TRUNC('MONTH', CURRENT_DATE) + INTERVAL '1 MONTHS' - INTERVAL '1 DAYS')::INTEGER

) AS T(I);

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG