Re: plpgsql loop not returning value - Mailing list pgsql-general

From Michael Fuhr
Subject Re: plpgsql loop not returning value
Date
Msg-id 20041016065934.GA19210@winnie.fuhr.org
Whole thread Raw
In response to plpgsql loop not returning value  (Josh Close <narshe@gmail.com>)
Responses Re: plpgsql loop not returning value
List pgsql-general
On Fri, Oct 15, 2004 at 10:56:06PM -0500, Josh Close wrote:

>     FOR this_rSum IN EXECUTE this_sQuery LOOP
>         this_iSum := this_rSum.isum;
>     END LOOP;
>     this_iTotal := this_iTotal + this_iSum;

[snip]

> If I return this_iSum or this_iTotal in the loop, I get a value. If I
> return directly after the loop, the value is NULL. I can't figure out
> why it's doing this. The value comes out of the inside for loop just
> fine, but not the outer loop.

Add some RAISE INFO statements to print variables' values at key
places.  I wonder if one of your SUMs is returning NULL, causing
your addition to evaluate to NULL.  If so, then perhaps you should
use COALESCE to turn those NULLs into zeros.

If I've misunderstood the problem then please clarify.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: William Yu
Date:
Subject: Re: creating audit tables
Next
From: "Katsaros Kwn/nos"
Date:
Subject: Re: Networking feature for postgresql...