From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: proposal: PL/Pythonu - function ereport |
Date: | 2015-10-15 18:47:25 |
Message-ID: | CAFj8pRDPKThnzaSXhjeKT-GroJQPXisPmA4n-iE=E3=7F8FunQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi
2015-10-09 15:22 GMT+02:00 Peter Eisentraut <peter_e(at)gmx(dot)net>:
> On 10/8/15 6:11 AM, Pavel Stehule wrote:
> > We cannot to raise PostgreSQL exception with setting all possible
> > fields.
>
> Such as? If there are fields missing, let's add them.
>
> > I propose new function
> >
> > plpy.ereport(level, [ message [, detail [, hint [, sqlstate, ... ]]]])
>
> That's not how Python works. If you want to cause an error, you should
> raise an exception.
>
>
I wrote a example, how to do it
postgres=# do $$
x = plpy.SPIError('Nazdarek');
x.spidata = (100, "Some detail", "some hint", None, None);
raise x;
$$ language plpythonu;
ERROR: T1000: plpy.SPIError: Nazdarek
DETAIL: Some detail
HINT: some hint
CONTEXT: Traceback (most recent call last):
PL/Python anonymous code block, line 4, in <module>
raise x;
PL/Python anonymous code block
LOCATION: PLy_elog, plpy_elog.c:106
Time: 1.170 ms
Is it some better way?
I see a few disadvantages
1. sqlcode is entered via integer
2. it doesn't allow keyword parameters - so we can second constructor of
SPIError
some like
postgres=# do $$
def SPIError(message, detail = None, hint = None):
x = plpy.SPIError(message)
x.spidata = (0, detail, hint, None, None)
return x
raise SPIError('Nazdar Svete', hint = 'Hello world');
$$ language plpythonu;
The main problem is a name for this function.
Regards
Pavel
From | Date | Subject | |
---|---|---|---|
Next Message | Claudio Freire | 2015-10-15 19:43:43 | Re: Duda |
Previous Message | Tom Lane | 2015-10-15 17:51:44 | Re: Re: [COMMITTERS] pgsql: Have dtrace depend on object files directly, not objfiles.txt |