CREATE TABLE AS inside of a function

Поиск
Список
Период
Сортировка
От Kevin Nikiforuk
Тема CREATE TABLE AS inside of a function
Дата
Msg-id 6EA72AC41F81D242A38AAF505523A94D022DF6@kappa.acrodex.net
обсуждение исходный текст
Ответы Re: CREATE TABLE AS inside of a function
Список pgsql-sql
So now that I've got my loops working, on to my next newbie question.  I've created my function and in it, I want to
loopthrough the results of a select and for each value of my loop counter, I want to create a new table, but I can't
figureout how to use a variable in the name of the new table, see below. 
CREATE OR REPLACE FUNCTION rgio() RETURNS INTEGER as $$
DECLARE        lv RECORD;
BEGIN       FOR lv IN SELECT DISTINCT rg FROM ldevrg LOOP               CREATE TABLE rgio_$lv AS
SELECTldev                        FROM ldevrg                        WHERE rg='$lv';       END LOOP; 
RETURN 1;
END;
$$ LANGUAGE plpgsql;

Thanks,
Kevin


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

Предыдущее
От: Scott Marlowe
Дата:
Сообщение: Re: System catalog table privileges
Следующее
От: "Rodrigo De Leon"
Дата:
Сообщение: Re: CREATE TABLE AS inside of a function