Re: Generic Function

From: George Weaver <gweaver(at)shaw(dot)ca>
To: lucas(at)presserv(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: Generic Function
Date: 2005-03-15 11:48:03
Message-ID: 004b01c52954$dacb5ec0$6400a8c0@Dell4500
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


----- Original Message -----
From: <lucas(at)presserv(dot)org>
To: <pgsql-sql(at)postgresql(dot)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
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2005-03-15 12:24:50 Re: How to force subquery scan?
Previous Message Richard Huxton 2005-03-15 10:36:06 Re: comparing 2 tables