From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Craig Ringer <craig(at)2ndquadrant(dot)com> |
Cc: | Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: proposal: PL/Pythonu - function ereport |
Date: | 2015-10-16 19:42:15 |
Message-ID: | CAFj8pRCh9UVJe4yQpBkZD+F8YEto_SbUjqO+TZG8P_xN_1NguQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
2015-10-16 8:12 GMT+02:00 Craig Ringer <craig(at)2ndquadrant(dot)com>:
> On 16 October 2015 at 02:47, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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
>
Attachment | Content-Type | Size |
---|---|---|
plpythonu-spierror-keyword-params.patch | text/x-patch | 16.7 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2015-10-16 19:45:54 | Re: checkpoint_segments upgrade recommendation? |
Previous Message | Andres Freund | 2015-10-16 19:38:25 | Re: proposal: DROP DATABASE variant that kills active sessions |