For In Execute

Поиск
Список
Период
Сортировка
От Jason Davis
Тема For In Execute
Дата
Msg-id 200108211304.XAA23003@zeus.tassie.net.au
обсуждение исходный текст
Ответы Re: For In Execute  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-novice
Hi all

I'm having some dramas getting a basic dynamic function to go, similar to
the one from Phillip Allen's posting from the other day...I'm attempting to
get the function to return the count(*) for a table name supplied to it:

CREATE FUNCTION test_func(text) RETURNS text AS '
DECLARE
  rec           record;
  retval        int;
  qry           text;
BEGIN
  qry:= ''SELECT COUNT(*) AS numrows FROM '' || $1 || '';'';
  FOR rec IN EXECUTE qry LOOP
    retval:= rec.numrows;
  END LOOP;
  RETURN retval;
END;
' LANGUAGE 'plpgsql';

The double quotes in the assignment to the qry variable are two single
quotes, if this is unclear. I get the following:

test=# select test_func('test_table');
NOTICE:  plpgsql: ERROR during compile of test_func near line 7
ERROR:  parse error at or near "EXECUTE"

After searching all the techdocs and the excellent Practical Postgresql and
other resources, I am still none the wiser...can anyone lend me a few brain
cells? I'm running 7.0.3.

cheers
Jason Davis


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

Предыдущее
От: "D. Duccini"
Дата:
Сообщение: Re: installing on sunos 5.7
Следующее
От: Tom Lane
Дата:
Сообщение: Re: For In Execute