Re: function with tablename parameter - Mailing list pgsql-general

From Stephan Szabo
Subject Re: function with tablename parameter
Date
Msg-id 20031027080310.B29441@megazone.bigpanda.com
Whole thread Raw
In response to function with tablename parameter  (Miso Hlavac <hlavki@medium13.sk>)
List pgsql-general
On Mon, 27 Oct 2003, Miso Hlavac wrote:

> hello,
>
> it is possible to write something similar???
>
> create function get_count(varchar(32)) RETURNS int4 AS '
> DECLARE
>   tmp int4;
> BEGIN
>   SELECT COUNT(*) INTO tmp FROM $1;
>   RETURN tmp;
> END;' LANGUAGE 'plpgsql';

Youll need to do something a little more complicated like:

create function get_count(varchar) RETURNS int8 AS '
DECLARE
 tmp record;
BEGIN
 FOR tmp IN EXECUTE ''SELECT COUNT(*) AS count FROM '' || $1 LOOP
  RETURN tmp.count;
 END LOOP;
END;'
LANGUAGE 'plpgsql';


pgsql-general by date:

Previous
From: Adam Witney
Date:
Subject: Re: table functions + user defined types
Next
From: "Chris M. Gamble"
Date:
Subject: Replication again