pl/python custom exceptions for SPI
От | Jan Urbański |
---|---|
Тема | pl/python custom exceptions for SPI |
Дата | |
Msg-id | 4D135F6B.6020809@wulczer.org обсуждение исходный текст |
Ответы |
Re: pl/python custom exceptions for SPI
|
Список | 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
Вложения
В списке pgsql-hackers по дате отправления: