Re: How to declare cursor if tablename is a variable?

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: How to declare cursor if tablename is a variable?
Дата
Msg-id 20070320034111.GA23662@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: How to declare cursor if tablename is a variable?  (Michael Fuhr <mike@fuhr.org>)
Список pgsql-sql
[Please copy the mailing list on replies so others can participate
in and learn from the discussion.]

On Tue, Mar 20, 2007 at 02:28:15AM +0000, hu js wrote:
> It doesn't work. Because can't use variable for table name in query.
> 
> Please tell me another way. Thanks

What exactly have you tried that doesn't work?  Will neither of the
following do what you want?  What version of PostgreSQL are you using?

DECLARE rec_obj    record; query_obj  text := 'SELECT mrc_xy_position FROM ' || quote_ident(tablename);
BEGIN FOR rec_obj IN EXECUTE query_obj LOOP   [...] END LOOP;

or

DECLARE cur_obj    refcursor; query_obj  text := 'SELECT mrc_xy_position FROM ' || quote_ident(tablename);
BEGIN OPEN cur_obj FOR EXECUTE query_obj; [...]

-- 
Michael Fuhr


В списке pgsql-sql по дате отправления:

Предыдущее
От: Paul Lambert
Дата:
Сообщение: Re: Issue with copying data from a text file.
Следующее
От: "remco lengers"
Дата:
Сообщение: ERROR: duplicate key violates unique constraint