Re: multiple CREATE FUNCTION AS items for PLs

From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: multiple CREATE FUNCTION AS items for PLs
Date: 2012-12-16 20:22:30
Message-ID: 50CE2D86.3060200@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 12/16/2012 08:44 PM, Andrew Dunstan wrote:
>
> On 12/16/2012 01:37 AM, Peter Eisentraut wrote:
>> So in practice this might look like this:
>>
>> CREATE FUNCTION foo(...) ... LANGUAGE plpythonu
>> AS $$
>> import x
>> import y
>> $$,
>> $$
>> real code here
>> $$;
>>
>
>
> Bleah.
>
> It seems obscure to say the least.
>
> Why not have something along the lines of plperl's on_init setting to
> load libraries? Among other things that would give you the advantage
> of being able to preload them, and also of some consistency among PLs.
>

While plpython.on_init is a much needed feature, it is orthogonal to
what is discussed here.

AIUI Peters proposal aimed adding per-function preparation /
initialisation not something
to be run for initialising the whole interpreter.

Also - to make the plpython.on_init really useful - there should be some
way to have python
_modules_ inside postgresql

If we would redefine plpython functions to define their own _visible_
modules (currently
each has its own module but there is no way to reference it from others)
and have the
function stored in this module we could not only solve the problem of
plpython modules
but also for calling other plpython modules directly from python .

for example, if doing

CREATE FUNCTION foo(i int) RETURNS int LANGUAGE plpythonu $$
def foo(i):
return i+1
$$;

would also make this function available as plpy.modules.foo_int.foo
(meaning its global
namespace would be saved as plpy.modules.foo_int

then other plpy functions could call it directly by doing

from plpy.modules.foo_int import foo

I try to come up with a more detailed proposal along these lines.

----------------------
Hannu

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2012-12-16 21:23:39 Re: multiple CREATE FUNCTION AS items for PLs
Previous Message Andrew Dunstan 2012-12-16 19:44:38 Re: multiple CREATE FUNCTION AS items for PLs