Re: PL/SQL: function call like $1($2)

Поиск
Список
Период
Сортировка
От David Fetter
Тема Re: PL/SQL: function call like $1($2)
Дата
Msg-id 20061009025343.GA1214@fetter.org
обсуждение исходный текст
Ответ на PL/SQL: function call like $1($2)  (Jean-Gerard Pailloncy <jg@rilk.com>)
Список pgsql-general
On Sun, Oct 08, 2006 at 05:49:11PM +0200, Jean-Gerard Pailloncy wrote:
> I want to create a function in PL/SQL as
> CREATE OR REPLACE FUNCTION "f_do" (text, double precision[]) RETURNS
> double precision AS '
> DECLARE
>     f text := $1;
>     p double precision[] := $2;
>     res double precision;
> BEGIN
>     SELECT f(p) into res;
>     RETURN res;
> END;' LANGUAGE "plpgsql"
> STABLE
> RETURNS NULL ON NULL INPUT
> SECURITY INVOKER
>
> But it does not work.
> I try EXECUTE f || ' ( ' || p || ' );' INTO res
> But is does not work too.
> There is no function to convert double precision[] to text.
>
> Is it possible to do this without converting the array of double to
> text ?

Here's one (WARNING! UNTESTED!) thing you might try.

CREATE OR REPLACE FUNCTION f_do (f text, p double precision[])
RETURNS double precision
LANGUAGE plpgsql
AS $$
DECLARE
    res double precision;
BEGIN
    CREATE FUNCTION f_do_inner (inner_p double precision[]) /* Do not attempt to replace */
    RETURNS double precision
    LANGUAGE plpgsql
    AS $q$
    BEGIN
        RETURN $q$ || quote_ident(f) || $q$(inner_p);
    END;
    $q$;

    SELECT INTO ret f_do_inner(p);

    DROP FUNCTION f_do_inner(inner_p double precision[]);

    RETURN ret;
END;
$$;

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

Remember to vote!

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: refcursor error 55000
Следующее
От: "Nikolay Samokhvalov"
Дата:
Сообщение: pg_dump VS alter database ... set search_path ...