Re: parsing SQLERRM ?

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: parsing SQLERRM ?
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C20800BCFA@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на parsing SQLERRM ?  (<david.sahagian@emc.com>)
Ответы Re: parsing SQLERRM ?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
david.sahagian@emc.com wrote:
> (version == 9.1)
>
> In my PL/pgSQL stored functions,
> I want to be able to distinguish which FK-constraint caused the
[foreign_key_violation] exception.
>   . . .
>   BEGIN
>     delete from MY_COOL_TABLE where id = 123 ;
>   EXCEPTION
>     WHEN foreign_key_violation THEN
>       CASE
>         WHEN (SQLERRM tells me it blew up because of FK X)  THEN . . .
;
>         WHEN (SQLERRM tells me it blew up because of FK Y)  THEN . . .
;
>         WHEN (SQLERRM tells me it blew up because of FK Z)  THEN . . .
;
>       END;
>     WHEN others THEN
>       raise;
>   END;
>   . . .
>
> Is a "robust enough" parsing of SQLERRM actually the best/only way to
determine this ?

I think so.

Not that it is particularly nice, though.  It should be fairly robust to
search for the name of the constraint in the error message.

Yours,
Laurenz Albe

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

Предыдущее
От: Jeff Davis
Дата:
Сообщение: Re: Reference with inheritance propagate data
Следующее
От: Léa Massiot
Дата:
Сообщение: Starting a cluster as a service