Re: BUG #14184: Function is running correct but not showing output

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #14184: Function is running correct but not showing output
Дата
Msg-id 17297.1465830357@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #14184: Function is running correct but not showing output  (zzia88@gmail.com)
Список pgsql-bugs
zzia88@gmail.com writes:
> CREATE OR REPLACE FUNCTION FACTORIAL(IN NUM BIGINT,OUT FACT BIGINT) AS $$
> DECLARE
>     FACT BIGINT;
>  BEGIN
>      FOR I IN REVERSE 1..NUM LOOP
>         FACT:=FACT*I;
>     END LOOP;
> END;
> $$ LANGUAGE plpgsql;

> SELECT* FROM FACTORIAL(5);

> IT SHOWING NULL VALUE...

Yes.  You didn't initialize FACT to something non-null (like, say, 1)
and multiplying null by anything will produce another null.

I think the REVERSE in your loop is wrong, too.

            regards, tom lane

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

Предыдущее
От: Kevin Grittner
Дата:
Сообщение: Re: BUG #14184: Function is running correct but not showing output
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #14184: Function is running correct but not showing output