RE: Python as a procedural language - Mailing list pgsql-interfaces

From Erny
Subject RE: Python as a procedural language
Date
Msg-id 3b0980f3@news
Whole thread Raw
In response to Python as a procedural language  (andrew@corvus.biomed.brown.edu (Andrew Bosma))
List 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 by date:

Previous
From: "Timothy H. Keitt"
Date:
Subject: Re: Subject: unbuffered results from libpq?
Next
From: v j
Date:
Subject: retrieval the history after psql command