Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id BF5879FB5DF for ; Wed, 14 Mar 2007 11:09:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 41515-04 for ; Wed, 14 Mar 2007 11:09:35 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 663289FB5D5 for ; Wed, 14 Mar 2007 11:09:41 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id l2EE9Zbi034982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 14 Mar 2007 07:09:37 -0700 (MST) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id l2EE9YDt007110; Wed, 14 Mar 2007 08:09:34 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id l2EE9YkE007109; Wed, 14 Mar 2007 08:09:34 -0600 (MDT) (envelope-from mfuhr) Date: Wed, 14 Mar 2007 08:09:34 -0600 From: Michael Fuhr To: hu js Cc: pgsql-sql@postgresql.org Subject: Re: How to declare cursor if tablename is a variable? Message-ID: <20070314140934.GA7086@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/194 X-Sequence-Number: 27832 On Wed, Mar 14, 2007 at 08:14:07AM +0000, hu js wrote: > CREATE or replace function geo_polygon(tablename varchar) RETURNS > [...] > cur_obj CURSOR FOR SELECT mrc_xy_position FROM tablename; > cur_point CURSOR FOR SELECT x,y FROM tablename where mrc_xy_position = > objectid; > > Error if call the function. Neither to use “execute” . Who can solve > it? Thanks! Are you sure you need to use cursors? Can you not build the query strings and use EXECUTE or "FOR variable IN EXECUTE query LOOP"? -- Michael Fuhr