Re: Date Math

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Date Math
Дата
Msg-id 17357.1178564423@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Date Math  (Adrian Klaver <aklaver@comcast.net>)
Ответы Re: Date Math  (Adrian Klaver <aklaver@comcast.net>)
Re: Date Math  (Rich Shepard <rshepard@appl-ecosys.com>)
Re: Date Math  (Rich Shepard <rshepard@appl-ecosys.com>)
Список pgsql-general
Adrian Klaver <aklaver@comcast.net> writes:
> With this setup you will have to use an explicit string-
> date_issued + INTERVAL  term|| 'years'. This will involve constructing a
> string and passing it to INTERVAL.

No, that's a truly awful way to do it.  The correct way is to use number
times interval multiplication, eg

    date_issued + term * '1 year'::interval;

This reduces to not much more than a floating-point multiply, whereas
the other way involves string-forming and string-parsing.  Plus you
can easily use whatever multiplier you like, eg '7 days' if weeks
strike your fancy.

It might be that converting those columns to interval is the best
answer, depending on what other processing needs to be done with them.
But if Rich wants to leave them as numbers, the above is the best way
to convert them to intervals on-the-fly.

            regards, tom lane

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

Предыдущее
От: Jeff Davis
Дата:
Сообщение: PITR and tar
Следующее
От: Andrew Kroeger
Дата:
Сообщение: Re: Slow query and indexes...