Re: BUG #14184: Function is running correct but not showing output - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #14184: Function is running correct but not showing output
Date
Msg-id 17297.1465830357@sss.pgh.pa.us
Whole thread Raw
In response to BUG #14184: Function is running correct but not showing output  (zzia88@gmail.com)
List 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 by date:

Previous
From: Kevin Grittner
Date:
Subject: Re: BUG #14184: Function is running correct but not showing output
Next
From: Tom Lane
Date:
Subject: Re: BUG #14184: Function is running correct but not showing output