BUG #14184: Function is running correct but not showing output
The following bug has been logged on the website:
Bug reference: 14184
Logged by: Zubair Alam
Email address: zzia88@gmail.com
PostgreSQL version: 9.5.3
Operating system: windows7-x64(64 bit)
Description:
postgresql-9.5.3-1-windows-x64
-----<<<<<<My function Coding>>>>----
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...
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
On Mon, Jun 13, 2016 at 8:40 AM, <zzia88@gmail.com> wrote:
-----<<<<<<My function Coding>>>>----
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...
FACT is NULL on declaration. NULL (unknown) multiplied by anything is NULL.
--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/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
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
zubair alam <zzia88@gmail.com> writes:
CREATE OR REPLACE FUNCTION FACTORIAL(IN NUM BIGINT,OUT FACT BIGINT) AS $$
DECLARE
FACT BIGINT:=1;
BEGIN
FOR I IN REVERSE 1..NUM LOOP
FACT:=FACT*I;
END LOOP;
END;
$$ LANGUAGE plpgsql;
if i am doing FACT BIGINT:=1; the also it giving the output NULL;
Well, the *third* bug in your function is that you're re-declaring
FACT as a local variable, thereby masking the output parameter.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Import Notes
Reply to msg id not found: CAPQXRnySfvCtA7y3MHoekVP-7rNoz0c2TSau3CVnN6RW04KRdw@mail.gmail.com