Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id BC6592E0060 for ; Wed, 12 Dec 2007 02:01:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 94711-04 for ; Wed, 12 Dec 2007 02:01:52 -0400 (AST) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 313D42E010B for ; Wed, 12 Dec 2007 02:01:52 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id lBC61pg7012743; Wed, 12 Dec 2007 01:01:51 -0500 (EST) To: Paul Lambert cc: pgsql-sql Subject: Re: Function result using execute In-reply-to: <475F6E69.3060207@reynolds.com.au> References: <475F6E69.3060207@reynolds.com.au> Comments: In-reply-to Paul Lambert message dated "Wed, 12 Dec 2007 14:15:21 +0900" Date: Wed, 12 Dec 2007 01:01:51 -0500 Message-ID: <12742.1197439311@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/62 X-Sequence-Number: 29754 Paul Lambert 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