Re: 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: Re: Table name as parameter in function
Date: 2004-11-23 23:32:58
Message-ID: 41A3C8A9.7030209@atlas.gis.univie.ac.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tim,

I'm afraid, I didn't get the point. Could you give me an example code
snippet of how to use the EXECUTE command in my case. Do I have to use
the EXECUTE within my function?

Thanks a lot,
alex.

Timothy Perrigo wrote:

> You'll need to use the EXECUTE command to build the SQL dynamically.
>
> See:
> http://www.postgresql.org/docs/7.4/interactive/plpgsql-
> statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
>
> On Nov 23, 2004, at 2:56 PM, Alexander Pucher wrote:
>
>> 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.
>>
>> ---------------------------(end of
>> broadcast)---------------------------
>> TIP 1: subscribe and unsubscribe commands go to
>> majordomo(at)postgresql(dot)org
>>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
>

--
--------------------------------------------------------
Departement of Geography and Regional Research
University of Vienna
Cartography and GIS
--------------------------------------------------------
Virtual Map Forum: http://www.gis.univie.ac.at/vmf
--------------------------------------------------------

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marc G. Fournier 2004-11-23 23:33:36 Re: Upcoming Changes to News Server ...
Previous Message Gary L. Burnore 2004-11-23 23:32:21 Re: Upcoming Changes to News Server ...