Re: BUG #5232: plpythonu s=s.op() raises an exception

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: BUG #5232: plpythonu s=s.op() raises an exception
Дата
Msg-id 1259884630.30348.3.camel@vanquo.pezone.net
обсуждение исходный текст
Ответ на Re: BUG #5232: plpythonu s=s.op() raises an exception  (David Gardner <dgardner@creatureshop.com>)
Ответы Re: BUG #5232: plpythonu s=s.op() raises an exception  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
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.

В списке pgsql-bugs по дате отправления:

Предыдущее
От: David Gardner
Дата:
Сообщение: Re: BUG #5232: plpythonu s=s.op() raises an exception
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #5232: plpythonu s=s.op() raises an exception