Re: help: now() + N is now failing!

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: help: now() + N is now failing!
Дата
Msg-id 21862.1059488983@sss.pgh.pa.us
обсуждение исходный текст
Ответ на help: now() + N is now failing!  ("Mel Jamero" <mel@gmanmi.tv>)
Список pgsql-novice
"Mel Jamero" <mel@gmanmi.tv> writes:
> help.  does anybody know how, without using date_pli, i can make now() + N
> work in newer versions of postgres?

Sure, make a custom operator.

regression=# select now() + 5;
ERROR:  operator does not exist: timestamp with time zone + integer
HINT:  No operator matches the given name and argument type(s). You may need to
add explicit typecasts.
regression=# create function tstz_plus_int(timestamp with time zone, int)
regression-# returns date as
regression-# 'select $1::date + $2' language sql;
CREATE FUNCTION
regression=# create operator + (
regression(# procedure = tstz_plus_int,
regression(# leftarg = timestamp with time zone,
regression(# rightarg = int);
CREATE OPERATOR
regression=# select now() + 5;
  ?column?
------------
 2003-08-03
(1 row)

regression=#

            regards, tom lane

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

Предыдущее
От: Nabil Sayegh
Дата:
Сообщение: Re: Retrieving NULL records
Следующее
От: Dmitry Tkach
Дата:
Сообщение: Re: help: now() + N is now failing!