Re: generate_series with month intervals

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Marcus Engene <mengpg(at)engene(dot)se>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: generate_series with month intervals
Date: 2007-01-11 20:32:14
Message-ID: 20070111203214.GB20521@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jan 11, 2007 at 20:07:29 +0100,
Marcus Engene <mengpg(at)engene(dot)se> wrote:
> Hi list,
>
> I'd like to generate the latest year dynamically with generate_series.
> This select works day wise:
>
> 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?

Are you just trying to get a list off the first of the month for the current
month and the next 11 months after that? For that you want to get the first
of the current month and then add s.a * '1 month' to it for 0 to 11.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeanna Geier 2007-01-11 21:09:58 RESTORE Error
Previous Message Bruce Momjian 2007-01-11 20:32:11 Re: ORDER BY col is NULL in UNION causes error?