Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

Remember to vote!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux