Re: using generate_series to iterate through months - Mailing list pgsql-general

From Tom Lane
Subject Re: using generate_series to iterate through months
Date
Msg-id 18132.1249314236@sss.pgh.pa.us
Whole thread Raw
In response to using generate_series to iterate through months  ("Bill Reynolds" <Bill.Reynolds@ateb.com>)
Responses Re: using generate_series to iterate through months  ("Bill Reynolds" <Bill.Reynolds@ateb.com>)
List pgsql-general
"Bill Reynolds" <Bill.Reynolds@ateb.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

pgsql-general by date:

Previous
From: Wojtek
Date:
Subject: Re: Partition tables
Next
From: Wojtek
Date:
Subject: Re: Partition tables