For In Execute

From: Jason Davis <jdavis(at)tassie(dot)net(dot)au>
To: pgsql-novice(at)postgresql(dot)org
Subject: For In Execute
Date: 2001-08-21 13:05:39
Message-ID: 200108211304.XAA23003@zeus.tassie.net.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2001-08-21 14:38:06 Re: For In Execute
Previous Message D. Duccini 2001-08-21 02:52:10 Re: installing on sunos 5.7