From: | Jan Urbański <wulczer(at)wulczer(dot)org> |
---|---|
To: | Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | pl/python custom exceptions for SPI |
Date: | 2010-12-23 14:40:43 |
Message-ID: | 4D135F6B.6020809@wulczer.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Here's a patch implementing custom Python exceptions for SPI errors
mentioned in
http://archives.postgresql.org/pgsql-hackers/2010-12/msg01991.php. It's
an incremental patch on top of the explicit-subxacts patch sent eariler.
Git branch for this patch:
https://github.com/wulczer/postgres/tree/custom-spi-exceptions.
What the patch does is provide a Python exception per each error defined
in utils/errcodes.h, and then raise the corresponding exception when a
SPI call fails. The parsing of errcodes.h in the Makefile is a little
grotty and would probably have to be ported to the Windows build system,
which I have no idea about.
With this patch you can do:
from plpy import spiexceptions
try:
plpy.execute("insert into t values (4)")
catch spiexceptions.UniqueViolation:
plpy.notice("unique constraint violation")
catch spiexceptions.NotNullViolation:
plpy.notice("not null constraint violation")
All exceptions inherint from plpy.SPIError, so code thta just catches a
blanket SPIErorr will continue to work.
The patch lacks user-facing docs, if it gets accepted I'll write some.
Not sure if we should provide a table similar to
http://www.postgresql.org/docs/current/static/errcodes-appendix.html, or
just refer to that table and state that the rule is changing underscores
to camel case...
Also, I just realised that this patch does not really depend on the
explicit-subxacts change, but rather only on the spi-in-subxacts, so if
need be I can generate it as an incremental changeset ofer the latter
and not the former.
Cheers,
Jan
Attachment | Content-Type | Size |
---|---|---|
plpython-custom-spi-exceptions.diff | text/x-patch | 18.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Li Jie | 2010-12-23 14:42:26 | Re: Why is sorting on two columns so slower thansortingon one column? |
Previous Message | Jan Urbański | 2010-12-23 14:32:02 | pl/python explicit subtransactions |