Re: Generic Function

Поиск
Список
Период
Сортировка
От George Weaver
Тема Re: Generic Function
Дата
Msg-id 004b01c52954$dacb5ec0$6400a8c0@Dell4500
обсуждение исходный текст
Ответ на Generic Function  (lucas@presserv.org)
Ответы Re: Generic Function  (lucas@presserv.org)
Список 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 по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: comparing 2 tables
Следующее
От: Christoph Haller
Дата:
Сообщение: Re: How to force subquery scan?