Table name as parameter in function

From: Alexander Pucher <pucher(at)atlas(dot)gis(dot)univie(dot)ac(dot)at>
To: PgSQL General List <pgsql-general(at)postgresql(dot)org>
Subject: Table name as parameter in function
Date: 2004-11-23 20:56:14
Message-ID: 41A3A3EE.5020301@atlas.gis.univie.ac.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

struggling around with this for some time:

How can I use a table name as a parameter in a PL/pgSQL function ??

I tried this but it didn't work...

CREATE OR REPLACE FUNCTION my_row_count(text) RETURNS int4 AS '
DECLARE
num_rows int4;
BEGIN
num_rows := (select count(*) from $1);
RETURN num_rows;
END;
' LANGUAGE plpgsql;

Thnaks for any input!

regards,
alex.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gary L. Burnore 2004-11-23 20:59:02 Re: Upcoming Changes to News Server ...
Previous Message Joshua D. Drake 2004-11-23 20:44:39 Re: Upcoming Changes to News Server ...