BUG #5232: plpythonu s=s.op() raises an exception - Mailing list pgsql-bugs

From David Gardner
Subject BUG #5232: plpythonu s=s.op() raises an exception
Date
Msg-id 200912032006.nB3K6xEV074074@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #5232: plpythonu s=s.op() raises an exception
List pgsql-bugs
The following bug has been logged online:

Bug reference:      5232
Logged by:          David Gardner
Email address:      dgardner@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'

pgsql-bugs by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Assertion failure with a subtransaction and cursor
Next
From: "Fredrik Palm"
Date:
Subject: Re: BUG #5229: Queing requests when not using psql