ANN: plpython - python integration with postgresql RDBMS

Christopher Lee clee at gnwy100.wuh.wustl.edu
Thu Apr 12 10:46:46 EDT 2001


FYI:

Andrew Bosma is working on integrating python with postgresql in order to
allow the use of python as a built-in procedural language for database
functions as you would with PL/pgSQL.  It's a work-in-progress but it looks
pretty cool and he's looking for feedback.  Source is available from
http://users.ids.net/~bosma/.  I would say these are "developer" releases:
compilation is a little tricky and may require that you build postgresql
7.1RC1 yourself.

-chris

To elaborate, plpython allows you to embed python into functions using the
form:

CREATE FUNCTION <function_name>(..) RETURNS <return_type> AS
<insert arbitrary python code>
LANGUAGE 'plpython'


For example, if you have a database which needs to maintain hashes of email
messages you might create a function like this:


CREATE FUNCTION handle_digest(text) RETURNS text
	AS
'import sha
digest = sha.new(args[0])
return digest.hexdigest()' LANGUAGE 'plpython';

You could then create a trigger that called this function to update the
hash using the CREATE TRIGGER.





More information about the Python-list mailing list