Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 707D82E3B62 for ; Wed, 12 Dec 2007 01:21:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 50668-01 for ; Wed, 12 Dec 2007 01:21:13 -0400 (AST) Received: from mail04.syd.optusnet.com.au (mail04.syd.optusnet.com.au [211.29.132.185]) by postgresql.org (Postfix) with ESMTP id 04B762E36E8 for ; Wed, 12 Dec 2007 01:15:44 -0400 (AST) Received: from [127.0.0.1] (online4-new.lnk.telstra.net [139.130.169.227]) (authenticated sender plengada@optusnet.com.au) by mail04.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id lBC5FdIe014740 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 12 Dec 2007 16:15:42 +1100 Message-ID: <475F6E69.3060207@reynolds.com.au> Date: Wed, 12 Dec 2007 14:15:21 +0900 From: Paul Lambert User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: pgsql-sql Subject: Function result using execute Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/61 X-Sequence-Number: 29753 I have a function which uses execute to populate the value of a variable based on a defined select construct. 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; RAISE NOTICE '%',curr_amount; I've added the if found to trap if nothing is returned by the execute so that the value gets set to a default 0 rather than null. When I call the function, the first raise notice gives me a value that is correct based on the select it would be performing, but the second raise notice gives me a 0, which suggests to me that although the execute has populated the curr_amount field with something, the IF NOT FOUND is always firing. Am I misunderstanding what the FOUND variable can be used for - i.e. is it not compatible with/not set by the EXECUTE command and should therefore I just be using a test of IF curr_amount IS NOT NULL? Cheers, Paul. -- Paul Lambert Database Administrator AutoLedgers - A Reynolds & Reynolds Company