From: Erny <aerd@mx3.redestb.es>
To: pgsql-interfaces@postgresql.org
Subject: RE: Python as a procedural language
Date: Mon, 21 May 2001 22:27:49 +0200
Message-ID: <3b0980f3@news> (raw)
References: <20010404211534.A13150@corvus.biomed.brown.edu>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: aerd@mx3.redestb.es
Subject: RE: Python as a procedural language
In-Reply-To: <3b0980f3@news>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox