Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id AFC9B9FBC32 for ; Fri, 23 Mar 2007 08:47:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 97702-05 for ; Fri, 23 Mar 2007 08:47:05 -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 299559FBBCF for ; Fri, 23 Mar 2007 08:47:09 -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 l2NBl4Zo047119 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Mar 2007 04:47:06 -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 l2NBl3UB085414; Fri, 23 Mar 2007 05:47:03 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id l2NBl33O085413; Fri, 23 Mar 2007 05:47:03 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 23 Mar 2007 05:47:03 -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: <20070323114703.GA76452@winnie.fuhr.org> Reply-To: pgsql-sql@postgresql.org Mail-Followup-To: pgsql-sql@postgresql.org References: <20070320034111.GA23662@winnie.fuhr.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/305 X-Sequence-Number: 27943 On Wed, Mar 21, 2007 at 02:20:21AM +0000, hu js wrote: > But I get into another trouble.See following program. As I requested before, please post questions to the mailing list so others can participate in and learn from the discussion. > "query_xypos" is ok. but "query_xydata" is not ok. > I find "objectid" not quoted corrected.It seems relevant with variable > varchar and "'". [...] > query_xypos text := 'SELECT mrc_xy_position FROM ' || > quote_ident(tablename); > query_xydata text := 'SELECT x,y FROM ' || tablename || ' where > mrc_xy_position = ' || quote_ident(objectid) ; See the documentation to learn more about quote_ident() and quote_literal() and when to use each: http://www.postgresql.org/docs/8.2/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN http://www.postgresql.org/docs/8.2/interactive/functions-string.html#FUNCTIONS-STRING-OTHER -- Michael Fuhr