2015-12-15 65 views
2

我試圖DATE對象以來1月1日的每一天generate a series,2014年PostgreSQL中創建一系列日期9.3

下面的查詢工作:

SELECT day::DATE FROM 
    (SELECT 
    generate_series('2014-01-01'::DATE, now(), '1 day') as day) sq; 
    day 
------------ 
2014-01-01 
2014-01-02 
2014-01-03 
2014-01-04 
2014-01-05 
2014-01-06 
2014-01-07 
2014-01-08 
2014-01-09 
2014-01-10 
2014-01-11 
2014-01-12 
... 
2015-12-13 
2015-12-14 
2015-12-15 
(714 rows) 

然而,子查詢似乎不雅對我來說。有沒有辦法直接從generate_series查詢中創建日期對象?

回答

1
select day::date 
from generate_series('2014-01-01'::date, now(), '1 day') sq (day) 
在選擇列表

或者直接:

select generate_series('2014-01-01'::date, now(), '1 day')::date as day 
+0

點上,AMIGO。謝謝! –