RE: Python as a procedural language

From: "Erny" <aerd(at)mx3(dot)redestb(dot)es>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: RE: Python as a procedural language
Date: 2001-05-21 20:27:49
Message-ID: 3b0980f3@news
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Erny 2001-05-21 20:41:30 RE: Postgres problem
Previous Message Timothy H. Keitt 2001-05-21 15:05:41 Re: Subject: unbuffered results from libpq?