From: | Adrian Klaver <aklaver(at)comcast(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Cc: | "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov> |
Subject: | Re: plpython and error catching |
Date: | 2007-11-20 02:31:00 |
Message-ID: | 200711191831.00263.aklaver@comcast.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Monday 19 November 2007 10:37 am, Sean Davis wrote:
> What is the expected behavior of a construct like this:
>
> def insert_xml(elem):
> id=int(elem.findtext('PMID'))
> try:
> plpy.execute(plan,[unicode(ET.tostring(elem)),id])
> except:
> plpy.execute(plan2,[unicode(ET.tostring(elem)),id])
>
> id is a primary key on the table into which I am inserting. "plan" is
> the execute plan for inserting new data. "plan2" is for updating data
> already in the database. When I run this, I am not able to catch
> errors of this type:
>
> WARNING: plpython: in function insert_medline_file:
> DETAIL: plpy.Error: Unknown error in PLy_spi_execute_plan
> ERROR: duplicate key value violates unique constraint "medlinexml_pkey"
> CONTEXT: SQL statement "insert into medlinexml(content,id) values
> (xmlparse(CONTENT $1),$2)"
>
> Why am I not able to catch this error and execute the update plan?
> The manual (8.3beta2) implies that errors generated in functions are
> genuine python errors that I should be able to catch.
>
> Thanks,
> Sean
You might want to take another look at the manual. It says an exception can be
raised from within the function and passed to the calling query by, unless
caught, by using plpy.error or plpy.fatal. In other words the opposite of
what you are counting on.
--
Adrian Klaver
aklaver(at)comcast(dot)net
From | Date | Subject | |
---|---|---|---|
Next Message | Sean Davis | 2007-11-20 03:10:16 | Re: plpython array support |
Previous Message | Jorge Godoy | 2007-11-20 02:08:50 | Re: plpython array support |