pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Python as a procedural language
2+ messages / 2 participants
[nested] [flat]

* Python as a procedural language
@ 2001-04-05 01:15  Andrew Bosma <andrew@corvus.biomed.brown.edu>
  0 siblings, 1 reply; 2+ messages in thread

From: andrew@corvus.biomed.brown.edu @ 2001-04-05 01:15 UTC (permalink / raw)
  To: pgsql-interfaces


Hi

I've coded up a module that implements python as a procedural language
for postgresql.  A tarball can be downloaded at

http://users.ids.net/~bosma

If anyone is interested, take a look at it.  Comments and suggestions
would be appreciated.  Functions and triggers work. The SPI interface
can run execute queries and saved plans.  I'm sure there's a bug or
three still lurking in there.  Installation instructions are in the
tarball.  The only complication is that for python to load its dynamic
modules without unresolved symbols, the flags passed to dlopen need to
be modified.  This means you will have to rebuild postgres.  Is there
any reason why the default dlopen is called without the RTLD_GLOBAL
flag?  (Actually you can build without modifying postgres, but that
requires explicitly linking python loadable modules to the language
module.)

Thanks
Andrew Bosma

-- 






^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* RE: Python as a procedural language
@ 2001-05-21 20:27  Erny <aerd@mx3.redestb.es>
  parent: Andrew Bosma <andrew@corvus.biomed.brown.edu>
  0 siblings, 0 replies; 2+ messages in thread

From: Erny @ 2001-05-21 20:27 UTC (permalink / raw)
  To: 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






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-05-21 20:27 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-05 01:15 Python as a procedural language Andrew Bosma <andrew@corvus.biomed.brown.edu>
2001-05-21 20:27 ` Erny <aerd@mx3.redestb.es>

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