Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCTRD-0006FT-5g for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Jun 2016 15:06:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bCTRC-0003GR-OC for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Jun 2016 15:06:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bCTRC-0003GA-A8 for pgsql-bugs@postgresql.org; Mon, 13 Jun 2016 15:06:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bCTR9-00006r-Cq for pgsql-bugs@postgresql.org; Mon, 13 Jun 2016 15:06:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u5DF5vEb017298; Mon, 13 Jun 2016 11:05:57 -0400 From: Tom Lane To: zzia88@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14184: Function is running correct but not showing output In-reply-to: <20160613134025.5792.79374@wrigleys.postgresql.org> References: <20160613134025.5792.79374@wrigleys.postgresql.org> Comments: In-reply-to zzia88@gmail.com message dated "Mon, 13 Jun 2016 13:40:25 -0000" Date: Mon, 13 Jun 2016 11:05:57 -0400 Message-ID: <17297.1465830357@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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