Hi Scott,
You'll have to execute dynamic SQL (see doc chapter "36.6.5. Executing
Dynamic Commands") for your function to work:
CREATE FUNCTION get_table_count(tablename text) RETURNS integer AS
$$
DECLARE --tablename ALIAS FOR $1; rowcount INTEGER; BEGIN
execute 'SELECT count(*) FROM '||tablename into rowcount; return rowcount;
END;
$$ LANGUAGE 'plpgsql';
select get_table_count('bar');
get_table_count
----------------- 3
(1 row)
Cheers,
--
Jean-Paul Argudo
www.PostgreSQLFr.org
www.dalibo.com