Re: How to track exceptions in PL/pgSQL

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: How to track exceptions in PL/pgSQL
Дата
Msg-id 20051012161132.GA35484@winnie.fuhr.org
обсуждение исходный текст
Ответ на How to track exceptions in PL/pgSQL  (Florian Ledoux <florian.ledoux@gmail.com>)
Список pgsql-general
On Wed, Oct 12, 2005 at 12:40:29PM +0200, Florian Ledoux wrote:
> I would like to track (timestamp and error number) in the database or
> in text files the exceptions that occur in my PL/pgSQL functions.
>
> 1. How can I retrieve the SQLCODE in a 8.0.3 PG server ?

You can't, at least not that I'm aware of.  In 8.1 you'll have
SQLSTATE and SQLERRM but they're not available in earlier versions.
I don't know if you could take the source code for 8.1's PL/pgSQL
and build it under 8.0; if not, then you might at least be able to
isolate the SQLSTATE/SQLERRM code and add it to 8.0's PL/pgSQL.
Perhaps one of the developers will comment about how feasible this
would be.

Without SQLSTATE/SQLERRM you could use several "WHEN some_exception
THEN" clauses to trap the most likely exceptions so at least you'd
know what kind of exception you were handling.

> 2. How can I trace the exception in a table although an implicit
> rollback is done when a exception occurs (the trace will be rollbacked
> too) ?

You should be able do inserts from the handler code.  It worked for
me in simple tests, so apparently the rollback is done before the
handler code is executed.

--
Michael Fuhr

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

Предыдущее
От: "codeWarrior"
Дата:
Сообщение: Re: user privilages for executing pg_autovacuum?
Следующее
От: "Reid Thompson"
Дата:
Сообщение: Postgresql Mention-- Logicworks' LogicOps Management and Monitoring Platform --Taking Linux, Apache, PostgreSQL, and PHP to their logical extreme