Re: generate_series with month intervals

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: generate_series with month intervals
Дата
Msg-id 28853.1168544159@sss.pgh.pa.us
обсуждение исходный текст
Ответ на generate_series with month intervals  (Marcus Engene <mengpg@engene.se>)
Ответы Re: generate_series with month intervals  (Marcus Engene <mengpg@engene.se>)
Список pgsql-general
Marcus Engene <mengpg@engene.se> 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Jonathan Hedstrom
Дата:
Сообщение: Re: ERROR: invalid memory alloc request size, and others
Следующее
От: "Patrick Earl"
Дата:
Сообщение: Re: Checkpoint request failed on version 8.2.1.