For In Execute - Mailing list pgsql-novice

From Jason Davis
Subject For In Execute
Date
Msg-id 200108211304.XAA23003@zeus.tassie.net.au
Whole thread Raw
Responses Re: For In Execute  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 by date:

Previous
From: "D. Duccini"
Date:
Subject: Re: installing on sunos 5.7
Next
From: Tom Lane
Date:
Subject: Re: For In Execute