2010-02-26

Global database configuration and context aware connection pool extention for psycopg2

Just created a recipe of the context aware connection pool that I am using for quite a long time now.

ActiveState Python Recipe #577072

Hope somebody would get at least some ideas for his own project.

2010-02-24

re-assigning values to the parameters in plpythonu

As discussed in Postgres BUG #5232 assigning values to the parameters fails with the following error:

Detail: <type 'exceptions.UnboundLocalError'>: local variable 'src' 
referenced before assignment

If assignment to the parameter is still needed one can solve the issue by adding global definition for such a parameter.

CREATE OR REPLACE FUNCTION pyreplace(src text, s text) 
  RETURNS text AS 
$BODY$ 
global src
src=src.replace(s,'') 
return src 
$BODY$ 
  LANGUAGE 'plpythonu' VOLATILE 
  COST 100;