generate_series with month intervals

From: Marcus Engene <mengpg(at)engene(dot)se>
To: pgsql-general(at)postgresql(dot)org
Subject: generate_series with month intervals
Date: 2007-01-11 19:07:29
Message-ID: 45A68AF1.6030202@engene.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi list,

I'd like to generate the latest year dynamically with generate_series.
This select works day wise:

select date_trunc ('month', now())::date + s.a
from generate_series(0, 11) as s(a)

I tried this but it didn't work:

select date_trunc ('month', now())::date + interval s.a || ' months'
from generate_series(0, 11) as s(a)

This works but looks grotesque:

select distinct date_trunc ('month', now()::date + s.a)::date
from generate_series(0, 365) as s(a)

Is there a way to do this more elegantly?

Best regards,
Marcus

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2007-01-11 19:20:08 pg_standby testing notes
Previous Message Merlin Moncure 2007-01-11 19:02:57 Re: Trying to load MySQL data