Re: How to 'register' functions, so they can be called (plpythonu)

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: How to 'register' functions, so they can be called (plpythonu)
Дата
Msg-id 20070905033239.GH23731@alvh.no-ip.org
обсуждение исходный текст
Ответ на How to 'register' functions, so they can be called (plpythonu)  ("blay bloo" <blaybloo@googlemail.com>)
Список pgsql-general
blay bloo wrote:
> I am defining some functions using plpythonu, through the standard means.
>
> Here I have one function (test1) which calls another (testfunc). When
> I excute this I get the following error:
>
> ERROR:  plpython: function "test1" failed
> DETAIL:  <type 'exceptions.NameError'>: global name 'testfunc' is not defined
>
> However, from the console, select testfunc('test') works fine.
>
> I was wondering how do I 'register'/'reference' these functions so
> that one function can call another?

You can't, because the name you give to the function lives in Postgres'
namespace, not Python's.  Therefore you can only call the other function
using the SPI interface that PL/Python offers you.

> I am guessing this is important,
> i.e. how will I access the complete functionality of the general
> python libs?

This is quite different -- I'm guessing the Python library can be
accessed via normal means.  What you cannot do is use Postgres' CREATE
FUNCTION to define a regular Python function (i.e. you cannot extend the
"library").

--
Alvaro Herrera                        http://www.advogato.org/person/alvherre
Bob [Floyd] used to say that he was planning to get a Ph.D. by the "green
stamp method," namely by saving envelopes addressed to him as 'Dr. Floyd'.
After collecting 500 such letters, he mused, a university somewhere in
Arizona would probably grant him a degree.              (Don Knuth)

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Documentation fix regarding atan2
Следующее
От: novice
Дата:
Сообщение: work hour calculations