From: George Weaver <gweaver@shaw.ca>
To: lucas@presserv.org
To: pgsql-sql@postgresql.org
Subject: Re: Generic Function
Date: Tue, 15 Mar 2005 05:48:03 -0600
Message-ID: <004b01c52954$dacb5ec0$6400a8c0@Dell4500> (raw)
References: <20050314151555.6kp8nfclzy5cogg0@www.presserv.org>
----- 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
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gweaver@shaw.ca, lucas@presserv.org
Subject: Re: Generic Function
In-Reply-To: <004b01c52954$dacb5ec0$6400a8c0@Dell4500>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox