我想使用PostgreSQL 9.3生成月份名单。
例如:
Months
---------
January
February
March
April
..
..
December
答案 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