Re: User defined exceptions

Поиск
Список
Период
Сортировка
От Alexey Bashtanov
Тема Re: User defined exceptions
Дата
Msg-id 55A8B097.8000303@imap.cc
обсуждение исходный текст
Ответ на User defined exceptions  (Alex Ignatov <a.ignatov@postgrespro.ru>)
Список pgsql-sql
On 15.07.2015 17:10, Alex Ignatov wrote:
> Hello all!
> Trying to emulate "named" user defined exception with:
> CREATE OR REPLACE FUNCTION exception_aaa ()  RETURNS text AS $body$
> BEGIN
>    return 31234;
> END;
> $body$
> LANGUAGE PLPGSQL
> SECURITY DEFINER
> ;
>
> do $$
> begin
>    raise exception using errcode=exception_aaa();
> exception
>    when  sqlstate exception_aaa()
>    then
>       raise notice 'got exception %',sqlstate;
> end;
> $$
>
> Got:
>
> ERROR:  syntax error at or near "exception_aaa"
> LINE 20: sqlstate exception_aaa()
>
> I looks like "when  sqlstate exception_aaa()" doesn't work.
>
> How can I catch exception in this case?

Hello Alex,

The following workaround could be used:

do $$
begin   raise exception using errcode = exception_aaa();
exception   when others then      if sqlstate = exception_aaa() then         raise notice 'got exception %',sqlstate;
  else         raise; --reraise      end if;
 
end;
$$

Not sure if its performance is the same as in simple exception catch, 
maybe it would degrade.

Best Regards,   Alexey Bashtanov



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

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: User defined exceptions
Следующее
От: Alex Ignatov
Дата:
Сообщение: Re: User defined exceptions