2015-10-16 8:12 GMT+02:00 Craig Ringer <cr...@2ndquadrant.com>:

> On 16 October 2015 at 02:47, Pavel Stehule <pavel.steh...@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") ?
>

postgres=# do $$
raise plpy.SPIError(msg="Message", sqlstate="0P001", hint="Turn it on and
off again");
$$ language plpythonu;
ERROR:  TypeError: SPIError does not take keyword arguments
CONTEXT:  Traceback (most recent call last):
  PL/Python anonymous code block, line 2, in <module>
    raise plpy.SPIError(msg="Message", sqlstate="0P001", hint="Turn it on
and off again");
PL/Python anonymous code block
Time: 1.193 ms



>
> 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.
>
>
postgres=# do $$
class cSPIError(plpy.SPIError):
        def __init__( self, message, detail = None, hint = None):
                self.spidata = (0, detail, hint, None, None,)
                self.args = ( message, )

x = cSPIError('Nazdarek', hint = 'some hint')
raise x
$$ language plpythonu;
ERROR:  cSPIError: Nazdarek
HINT:  some hint
CONTEXT:  Traceback (most recent call last):
  PL/Python anonymous code block, line 8, in <module>
    raise x
PL/Python anonymous code block

This code is working, so it needs explicit constructor for class SPIError

Regards

Pavel


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

Reply via email to