pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14184: Function is running correct but not showing output
4+ messages / 3 participants
[nested] [flat]
* BUG #14184: Function is running correct but not showing output
@ 2016-06-13 13:40 zzia88@gmail.com
0 siblings, 2 replies; 4+ messages in thread
From: zzia88@gmail.com @ 2016-06-13 13:40 UTC (permalink / raw)
To: pgsql-bugs
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #14184: Function is running correct but not showing output
@ 2016-06-13 15:03 Kevin Grittner <kgrittn@gmail.com>
parent: zzia88@gmail.com
1 sibling, 0 replies; 4+ messages in thread
From: Kevin Grittner @ 2016-06-13 15:03 UTC (permalink / raw)
To: zzia88@gmail.com; +Cc: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #14184: Function is running correct but not showing output
@ 2016-06-13 15:05 Tom Lane <tgl@sss.pgh.pa.us>
parent: zzia88@gmail.com
1 sibling, 1 reply; 4+ messages in thread
From: Tom Lane @ 2016-06-13 15:05 UTC (permalink / raw)
To: zzia88@gmail.com; +Cc: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #14184: Function is running correct but not showing output
@ 2016-06-13 15:25 Tom Lane <tgl@sss.pgh.pa.us>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2016-06-13 15:25 UTC (permalink / raw)
To: zubair alam <zzia88@gmail.com>; +Cc: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2016-06-13 15:25 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-06-13 13:40 BUG #14184: Function is running correct but not showing output zzia88@gmail.com
2016-06-13 15:03 ` Kevin Grittner <kgrittn@gmail.com>
2016-06-13 15:05 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-06-13 15:25 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox