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

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Michael Fuhr" <mike(at)fuhr(dot)org>
Cc: "Jean-Gerard Pailloncy" <jg(at)rilk(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: PL/SQL: function call like $1($2)
Date: 2006-10-09 14:32:58
Message-ID: b42b73150610090732n6e229379vf6d3e12f9ad89e2d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/9/06, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
> On Sun, Oct 08, 2006 at 05:49:11PM +0200, Jean-Gerard Pailloncy wrote:
> > I try EXECUTE f || ' ( ' || p || ' );' INTO res
> > But is does not work too.
> > There is no function to convert double precision[] to text.
>
> You could use the types' input and output functions or perhaps
> array_to_string().
>
> stmt := 'SELECT ' || quote_ident(f) || '(' || quote_literal(textin(array_out(p))) || ')';
> EXECUTE stmt INTO res;

thinking about this some more, it looks like the basic issue is
passing in function to operate over a defined type, sort of like a sql
closure. This can be rigged in dynamic sql but this has couple
problems. Complex types are a pain (record types are even worse) and
dynamic sql feels like a kludge anyhow. Here is maybe another
solution:

you can make a make an oid from a string:
esilo=# create function foo() returns void as $$ ; $$ language sql;
CREATE FUNCTION
esilo=# select 'foo()'::regprocedure::oid;
oid
--------
300009
(1 row)

whierle the is no way to call a function via its oid in pl/pgsql, it
is fairly trivial from C and somewhat generic using
OidFunctionCall1(): (or 2, etc)

http://www.nabble.com/improvise-callbacks-in-plpgsql-tf476925.html#a1299810

I have tested this approach, and it works!

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-10-09 14:36:26 Re: Fwd: pg_dump VS alter database ... set search_path ...
Previous Message Tom Lane 2006-10-09 14:28:04 Re: column privileges