Re: Generic Function - Mailing list pgsql-sql

From George Weaver
Subject Re: Generic Function
Date
Msg-id 004b01c52954$dacb5ec0$6400a8c0@Dell4500
Whole thread Raw
In response to Generic Function  (lucas@presserv.org)
Responses Re: Generic Function  (lucas@presserv.org)
List pgsql-sql
----- Original Message ----- 
From: <lucas@presserv.org>
To: <pgsql-sql@postgresql.org>
Sent: Monday, March 14, 2005 12:15 PM
Subject: [SQL] Generic Function


> Hi,
> Can I built a generic function like:
> CREATE FUNCTION f (text) RETURNS TEXT as
>  $$
>   return 'select * from $1';
>  $$
> I know its impossible as writed. Also I have looked for EXECUTE procedure 
> but it
> not run the correct function.

If you show us what you've tried and the results you received we may be able 
to help more.

Some points:
    1. To create a string to run with EXECUTE you would need to concatenate 
the above phrase:
        (Assuming "query" has been declared as text): query := 'Select * 
from ' || $1;
   2. Since you're likely returning multiple rows, you need to write your 
function as a set-returning       function.  See:
   http://www.postgresql.org/docs/8.0/static/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING
     and Executing Dynamic Commands in
   http://www.postgresql.org/docs/8.0/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-PERFORM

> Is there a way to construct this clause? Using plpgsql/pltcl/anything.... 
> ???
>
> Thanks
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faq
> 




pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: comparing 2 tables
Next
From: Christoph Haller
Date:
Subject: Re: How to force subquery scan?