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 
global src
return src 
  LANGUAGE 'plpythonu' VOLATILE 
  COST 100; 

No comments: