Re: INTERVAL in a function

Поиск
Список
Период
Сортировка
От Ron St-Pierre
Тема Re: INTERVAL in a function
Дата
Msg-id 4190F93C.7060905@syscor.com
обсуждение исходный текст
Ответ на Re: INTERVAL in a function  (Michael Fuhr <mike@fuhr.org>)
Список pgsql-general
Michael Fuhr wrote:

>On Mon, Nov 08, 2004 at 04:15:34PM -0800, Ron St-Pierre wrote:
>
>
>
>>SELECT INTO exptime current_timestamp + INTERVAL ''intval'';
>>
>>
>
>You're using the literal value 'intval' instead of its value, thus
>the syntax error.
>
Of course, I should have caught that.

>You can simplify the statement to this:
>
>exptime := current_timestamp + intval;
>
>But I think the entire function can be shortened to:
>
>CREATE OR REPLACE FUNCTION getUnitTimeLength(int) RETURNS TIMESTAMP AS '
>SELECT CURRENT_TIMESTAMP::timestamp + unitTimeLength
>FROM customer.groups
>WHERE groupsID = $1
>' LANGUAGE sql;
>
>You don't need to check for NULL because the result of the addition
>will already be NULL if either operand is NULL.  Casting CURRENT_TIMESTAMP
>is necessary to avoid a "return type mismatch" error.
>
>
>
Perfect.
 Thanks Michael!


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

Предыдущее
От: Oliver Elphick
Дата:
Сообщение: Re: server auto-restarts and ipcs
Следующее
От: "Tk421"
Дата:
Сообщение: Re: Functions in postgres