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

From: David Fetter <david(at)fetter(dot)org>
To: Jean-Gerard Pailloncy <jg(at)rilk(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PL/SQL: function call like $1($2)
Date: 2006-10-09 02:53:43
Message-ID: 20061009025343.GA1214@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Nikolay Samokhvalov 2006-10-09 08:45:16 pg_dump VS alter database ... set search_path ...
Previous Message Tom Lane 2006-10-08 20:48:48 Re: refcursor error 55000