X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 716EC5E46EC for ; Wed, 18 Aug 2004 22:36:00 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30092-05 for ; Thu, 19 Aug 2004 01:36:09 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 3831E5E46D6 for ; Wed, 18 Aug 2004 22:35:58 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i7J1a9PI006772; Wed, 18 Aug 2004 21:36:10 -0400 (EDT) To: Theo Galanakis Cc: pgsql-sql@postgresql.org Subject: Re: Function Issue! In-reply-to: <82E30406384FFB44AFD1012BAB230B55037D051E@shiva.au.lpint.net> References: <82E30406384FFB44AFD1012BAB230B55037D051E@shiva.au.lpint.net> Comments: In-reply-to Theo Galanakis message dated "Thu, 19 Aug 2004 11:10:00 +1000" Date: Wed, 18 Aug 2004 21:36:09 -0400 Message-ID: <6771.1092879369@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200408/218 X-Sequence-Number: 18715 Theo Galanakis writes: > Can anyone tell me what is wrong with the function below ? > CREATE OR REPLACE FUNCTION "public"."theo_test2" () RETURNS OPAQUE AS' > BEGIN > declare curr_theo cursor for select * from node_names; > fetch next from curr_theo; > close curr_theo; > END; > 'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY DEFINER; The DECLARE has to go before the BEGIN: CREATE OR REPLACE FUNCTION "public"."theo_test2" () RETURNS OPAQUE AS' DECLARE curr_theo cursor for select * from node_names; BEGIN fetch next from curr_theo; close curr_theo; END; 'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY DEFINER; I think you are missing an OPEN step too, and the FETCH syntax is wrong for plpgsql. Read the plpgsql doc section about using cursors --- it is not at all identical to what you do in plain SQL. regards, tom lane