----- Original Message ----- From: <[EMAIL PROTECTED]>
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
---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]