Re: selecting table at execution with PL/PgSQL

Поиск
Список
Период
Сортировка
От Gianni Mariani
Тема Re: selecting table at execution with PL/PgSQL
Дата
Msg-id 3F905A7E.2020608@mariani.ws
обсуждение исходный текст
Ответ на selecting table at execution with PL/PgSQL  ("Bill Nedell" <bill@wynde.com>)
Список pgsql-general
Bill Nedell wrote:
I am trying to write a PL/PgSQL function that can be given a table name as an argument at execution time and I don't see any way of doing it. I want the user to be able to specify the table dynamically when the function is run.
 
As an example, if I try the following:
 
CREATE OR REPLACE FUNCTION scrub() RETURNS VARCHAR AS '
DECLARE
    tl pg_tables%ROWTYPE;
BEGIN
    FOR tl IN SELECT * FROM pg_tables LOOP
    RAISE INFO ''table %'', tl.tablename;
    SELECT * FROM tl.tablename;
Try EXECUTE 'SELECT ....

where the execute parameter is created by assembling the select statement string.

It's all in the documentation.

http://www.postgresql.org/docs/7.3/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN-QUERIES


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

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Writers Wanted
Следующее
От: Greg Stark
Дата:
Сообщение: Re: ShmemAlloc errors