Re: BUG #5232: plpythonu s=s.op() raises an exception
От | David Gardner |
---|---|
Тема | Re: BUG #5232: plpythonu s=s.op() raises an exception |
Дата | |
Msg-id | 4B183FC7.5070403@creatureshop.com обсуждение исходный текст |
Ответ на | Re: BUG #5232: plpythonu s=s.op() raises an exception (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: BUG #5232: plpythonu s=s.op() raises an exception
|
Список | pgsql-bugs |
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 ********** Error ********** ERROR: PL/Python: PL/Python function "pyreplacenotry" failed SQL state: XX000 Detail: <type 'exceptions.UnboundLocalError'>: local variable 'src' referenced before assignment However this works: CREATE OR REPLACE FUNCTION pyreplacenoreassign(src text, s text) RETURNS text AS $BODY$ return src.replace(s,'') $BODY$ LANGUAGE 'plpythonu' VOLATILE COST 100; ALTER FUNCTION pyreplacenoreassign(text, text) OWNER TO dgardner; Tom Lane wrote: > "David Gardner" <dgardner@creatureshop.com> writes: > >> 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; >> > > Weird. You seem to need both the try block and the overwrite of the > parameter to make it misbehave. I suspect this means we're doing > something a bit wrong in setting up the python variable for the > parameter. Unfortunately I don't know enough about python to go further > than that. > > regards, tom lane > > -- David Gardner Pipeline Tools Programmer Jim Henson Creature Shop dgardner@creatureshop.com
В списке pgsql-bugs по дате отправления: