On tor, 2009-12-03 at 14:46 -0800, David Gardner wrote:
> Not sure about the try block being related, I included it in my
> example mostly because the example is a simplified version of some
> code I was working on that had a try/except block. 
> I tried the function without the try block and it raised the same
> exception (just uncaught):
> 
> CREATE OR REPLACE FUNCTION pyreplacenotry(src text, s text)
>   RETURNS text AS
> $BODY$
> src=src.replace(s,'')
> return src
> $BODY$
>   LANGUAGE 'plpythonu' VOLATILE
>   COST 100;
> ALTER FUNCTION pyreplacenotry(text, text) OWNER TO dgardner;
> 
> gives me:
> ERROR:  PL/Python: PL/Python function "pyreplacenotry" failed
> DETAIL:  <type 'exceptions.UnboundLocalError'>: local variable 'src'
> referenced before assignment

What is going on internally is something like this:

src = 'xyz'

def pyreplacenotry():
    src=src.replace('x', 'y')
    return src

pyreplacenotry()

which fails with that same error.  So you should not try to assign to
the parameters of a function.



-- 
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