Re: multiple CREATE FUNCTION AS items for PLs

Поиск
Список
Период
Сортировка
От Hannu Krosing
Тема Re: multiple CREATE FUNCTION AS items for PLs
Дата
Msg-id 50CE2D86.3060200@2ndQuadrant.com
обсуждение исходный текст
Ответ на Re: multiple CREATE FUNCTION AS items for PLs  (Andrew Dunstan <andrew@dunslane.net>)
Список 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








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

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: Re: multiple CREATE FUNCTION AS items for PLs
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: multiple CREATE FUNCTION AS items for PLs