RE: Python as a procedural language

Поиск
Список
Период
Сортировка
От Erny
Тема RE: Python as a procedural language
Дата
Msg-id 3b0980f3@news
обсуждение исходный текст
Ответ на Python as a procedural language  (andrew@corvus.biomed.brown.edu (Andrew Bosma))
Список pgsql-interfaces
Hi,

i compiled and installed this.

I wonder how you would write a recursive function such as:

CREATE FUNCTION factx(int4) RETURNS int4 AS '
def f(n):   if n==0:       return 1   else:       return n*f(n-1)
return f(args[0])
' LANGUAGE 'plpython';

When called, it crashes in the       return n*f(n-1)
line, not knowing what f is. I could fix that using SD like this:
CREATE FUNCTION factx(int4) RETURNS int4 AS '
def f(n):   if n==0:       return 1   else:       return n*SD["f"](n-1)
SD["f"]=f
return f(args[0])
' LANGUAGE 'plpython';

Or putting the function as attribute of pgpy.

What happens to the namespace?

Erny
Spain





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

Предыдущее
От: "Timothy H. Keitt"
Дата:
Сообщение: Re: Subject: unbuffered results from libpq?
Следующее
От: v j
Дата:
Сообщение: retrieval the history after psql command