Re: using generate_series to iterate through months

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Bill Reynolds" <Bill(dot)Reynolds(at)ateb(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: using generate_series to iterate through months
Date: 2009-08-03 15:43:56
Message-ID: 18132.1249314236@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Bill Reynolds" <Bill(dot)Reynolds(at)ateb(dot)com> writes:
> Ok, I'm a bit stumped on getting my group by query to work which
> iterates through a number of months that basically a generate_series
> provides for me.
> ...
> select DATE('2008-05-01') + interval (s.a??? ' months') as Month_of

No, you're confusing a syntax that's meant to handle literal constants
with something that's appropriate for computation. What you want is

> select DATE('2008-05-01') + s.a * interval '1 month' as Month_of

that is, multiply the sequence output by a suitable interval constant.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Maracini 2009-08-03 15:46:30 \copy command error
Previous Message Wojtek 2009-08-03 15:18:20 Re: Partition tables