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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: zzia88(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14184: Function is running correct but not showing output
Date: 2016-06-13 15:05:57
Message-ID: 17297.1465830357@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

zzia88(at)gmail(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2016-06-13 15:25:24 Re: BUG #14184: Function is running correct but not showing output
Previous Message Kevin Grittner 2016-06-13 15:03:54 Re: BUG #14184: Function is running correct but not showing output