開始日と終了日を指定して、一連の四半期を生成する必要があります。私は知ってgenerate_series()
いますが、それはうまくいきませんquarter
:
SELECT * FROM generate_series('2008-01-01 00:00'::timestamp,'2009-01-01 12:00', '1 quarter');
この四半期が特別な理由は何ですか? それ以外の場合generate_series()
は、マイクロ秒からミレニアムまで、ほとんどすべてで機能します。
select * from generate_series('2008-01-01 00:00'::timestamp,'2008-01-01 00:00:00.001', '1 microsecond');
select * from generate_series('2008-01-01 00:00'::timestamp,'2008-01-01 00:01', '1 second');
select * from generate_series('2008-01-01 00:00'::timestamp,'2008-01-01 01:00', '1 minute');
select * from generate_series('2008-01-01 00:00'::timestamp,'2008-01-01 12:00', '1 hour');
select * from generate_series('2008-01-01 00:00'::timestamp,'2009-01-01 12:00', '1 day');
select * from generate_series('2008-01-01 00:00'::timestamp,'2009-01-01 12:00', '1 week');
select * from generate_series('2008-01-01 00:00'::timestamp,'2009-01-01 12:00', '1 month');
select * from generate_series('2008-01-01 00:00'::timestamp,'2009-01-01 12:00', '1 year');
select * from generate_series('2008-01-01 00:00'::timestamp,'2009-01-01 12:00', '1 decade');
select * from generate_series('2008-01-01 00:00'::timestamp,'2009-01-01 12:00', '1 century');
select * from generate_series('2008-01-01 00:00'::timestamp,'2009-01-01 12:00', '1 millennium');
quarter
使用できない場合、他の最適なオプションは何ですか? 今のところ、私は持っています:
select
date_trunc('quarter',generate_series) gs
from
generate_series('2008-01-01 00:00'::timestamp,'2009-01-01 12:00', '1 month')
group by
gs
order by
gs;