Re: How to declare cursor if tablename is a variable? - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: How to declare cursor if tablename is a variable?
Date
Msg-id 20070323114703.GA76452@winnie.fuhr.org
Whole thread Raw
In response to Re: How to declare cursor if tablename is a variable?  (Michael Fuhr <mike@fuhr.org>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: "Ezequias R. da Rocha"
Date:
Subject: Re: Dummy question
Next
From: "Wilkinson, Jim"
Date:
Subject: Selecting different views from a Boolean expression