The following bug has been logged online:

Bug reference:      5232
Logged by:          David Gardner
Email address:      dgard...@creatureshop.com
PostgreSQL version: 8.4.1
Operating system:   Debian, amd64
Description:        plpythonu s=s.op() raises an exception
Details: 

If I create the following:
CREATE OR REPLACE FUNCTION pyreplace(src text,s text)
  RETURNS text AS
$BODY$
try:
    src=src.replace(s,'')
    return src
except Exception,e:
    return str(e)
$BODY$
  LANGUAGE 'plpythonu' VOLATILE
  COST 100;
ALTER FUNCTION pyreplace(src text,s text) OWNER TO dgardner;

Then:
SELECT * FROM pyreplace('this is a very long string','is');
                     pyreplace                     
---------------------------------------------------
 local variable 'src' referenced before assignment
(1 row)


However in python I can do:
def pyreplace(src,s):
    try:
        src=src.replace(s,'')
        return src
    except Exception,e:
        return str(e)
    
pyreplace('this is a very long string','is')
-----
produces:
'th  a very long string'

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to