Re: Function result using execute

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Paul Lambert <paul(dot)lambert(at)reynolds(dot)com(dot)au>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Function result using execute
Date: 2007-12-12 06:01:51
Message-ID: 12742.1197439311@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Paul Lambert <paul(dot)lambert(at)reynolds(dot)com(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Erik Jones 2007-12-12 06:25:10 Re: Function result using execute
Previous Message Paul Lambert 2007-12-12 05:15:21 Function result using execute