PostgreSQL 9.3:生成月份名称列表

时间:2015-03-02 11:10:06

标签: postgresql postgresql-9.3

我想使用PostgreSQL 9.3生成月份名单。

例如:

Months
---------
January
February
March
April
..
..
December

2 个答案:

答案 0 :(得分:3)

select to_char(m, 'Month')
from generate_series(
    '2014-01-01'::date, '2014-12-31', '1 month'
) s(m);
  to_char  
-----------
 January  
 February 
 March    
 April    
 May      
 June     
 July     
 August   
 September
 October  
 November 
 December 

答案 1 :(得分:0)

1

select to_char(to_timestamp (m::text, 'MM'), 'Month')
from generate_series(
    1, 12, 1
) s(m)

2

with recursive
t as (
select 1 n union select n + 1 from t where n < 12
)
select to_char(to_timestamp (n::text, 'MM'), 'Month') from t