Re: Function result using execute - Mailing list pgsql-sql

From Tom Lane
Subject Re: Function result using execute
Date
Msg-id 12742.1197439311@sss.pgh.pa.us
Whole thread Raw
In response to Function result using execute  (Paul Lambert <paul.lambert@reynolds.com.au>)
Responses Re: Function result using execute
List pgsql-sql
Paul Lambert <paul.lambert@reynolds.com.au> writes:
> The relevant part of the code looks like thus:
>     EXECUTE curr_query INTO curr_amount;
>     RAISE NOTICE '%',curr_amount;
>     IF NOT FOUND THEN
>        curr_amount=0;
>     END IF;

> ... which suggests to me that although the 
> execute has populated the curr_amount field with something, the IF NOT 
> FOUND is always firing.

IIRC, the EXECUTE command does not change FOUND --- leastwise it's not
listed as one of the plpgsql commands that do set FOUND.

Do you really need an EXECUTE?  If so, maybe you could restructure this
using a FOR ... IN EXECUTE, or some such thing.

> therefore I just be using a test of IF curr_amount IS NOT NULL?

Well, that might work.  Have you thought through the corner case
where the query does find a row but the field's value is null?
        regards, tom lane


pgsql-sql by date:

Previous
From: Paul Lambert
Date:
Subject: Function result using execute
Next
From: Erik Jones
Date:
Subject: Re: Function result using execute