Re: proposal: PL/Pythonu - function ereport
От | Pavel Stehule |
---|---|
Тема | Re: proposal: PL/Pythonu - function ereport |
Дата | |
Msg-id | CAFj8pRDPKThnzaSXhjeKT-GroJQPXisPmA4n-iE=E3=7F8FunQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: proposal: PL/Pythonu - function ereport (Peter Eisentraut <peter_e@gmx.net>) |
Ответы |
Re: proposal: PL/Pythonu - function ereport
|
Список | pgsql-hackers |
Hi
Regards
2015-10-09 15:22 GMT+02:00 Peter Eisentraut <peter_e@gmx.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
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.
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.
Pavel
В списке pgsql-hackers по дате отправления: