Re: proposal: PL/Pythonu - function ereport

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: proposal: PL/Pythonu - function ereport
Дата
Msg-id CAFj8pRCh9UVJe4yQpBkZD+F8YEto_SbUjqO+TZG8P_xN_1NguQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: proposal: PL/Pythonu - function ereport  (Craig Ringer <craig@2ndquadrant.com>)
Ответы Re: proposal: PL/Pythonu - function ereport  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-hackers


2015-10-16 8:12 GMT+02:00 Craig Ringer <craig@2ndquadrant.com>:
On 16 October 2015 at 02:47, Pavel Stehule <pavel.stehule@gmail.com> wrote:

>  postgres=# do $$
> x = plpy.SPIError('Nazdarek');
> x.spidata = (100, "Some detail", "some hint", None, None);
> raise x;
> $$ language plpythonu;

Shouldn't that look more like

raise plpy.SPIError(msg="Message", sqlstate="0P001", hint="Turn it on
and off again") ?

Keyword args are very much the norm for this sort of thing. I recall
them being pretty reasonable to deal with in the CPython API too, but
otherwise a trivial Python wrapper in the module can easily adapt the
interface.

I wrote a constructor for SPIError with keyword parameters support - see attached patch

The code is working

 postgres=# do $$
raise plpy.SPIError("pokus",hint = "some info");
$$ language plpythonu;
ERROR:  plpy.SPIError: pokus
HINT:  some info
CONTEXT:  Traceback (most recent call last):
  PL/Python anonymous code block, line 2, in <module>
    raise plpy.SPIError("pokus",hint = "some info");
PL/Python anonymous code block

but the implementation is pretty ugly :( - I didn't write C extensions for Python before, and the extending exception class with some methods isn't well supported and well documented.

Any help is welcome

Regards

Pavel




--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Вложения

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

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: proposal: DROP DATABASE variant that kills active sessions
Следующее
От: Robert Haas
Дата:
Сообщение: Re: checkpoint_segments upgrade recommendation?