Search Postgresql Archives

Re: generate_series with month intervals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Marcus Engene <mengpg@xxxxxxxxx> writes:
> 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)

People keep trying that :-(.  The "typename 'foo'" syntax is for a
*literal constant* only.  Instead use multiplication, something like

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

You'll want the cast back to date as the last step here because
date+interval will give timestamp.

			regards, tom lane


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux