MAK
MAK

Reputation: 7270

PostgreSQL 9.3: Generate months name list

I want to generate months names list using PostgreSQL 9.3.

For example:

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

Upvotes: 0

Views: 826

Answers (2)

DanStopka
DanStopka

Reputation: 565

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

Upvotes: 0

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125574

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 

Upvotes: 3

Related Questions