proposal: enhanced get diagnostics statement

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: proposal: enhanced get diagnostics statement
Date: 2011-05-21 20:05:01
Message-ID: BANLkTikcOxJRB0HvKakHOJsJS3kgf4p6sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

This proposal is related to exception processing. Inside exception
handler we can get some basic info about exception - message text and
message code. There are other fields - but these fields are no
available now in PL/pgSQL. The cheap access to fields inside ErrorData
structure can be implemented inside GET DIAGNOSTICS statements - this
statement is created for this purpose. I propose a new thee
identifiers, that can be used there: ERROR_DETAIL, ERROR_HINT and
ERROR_CONTEXT. Using is simple:

CREATE OR REPLACE FUNCTION foo()
RETURNS void AS $$
DECLARE
_detail text;
_hint text;
_context text;
BEGIN
RAISE EXCEPTION 'some message'
USING DETAIL = 'some message specific description',
HINT = 'some hint related to messgae';

EXCEPTION WHEN OTHERS THEN
GET DIAGNOSTICS _detail = ERROR_DETAIL,
_hint = ERROR_HINT,
_context = ERROR_CONTEXT;

RAISE WARNING 'caught message: %', SQLERRM
USING DETAIL = e'\ncaught detail: ' || _detail ||
e'\ncaught hint: ' || _hint ||
e'\ncaught context: ' || _context;

END;
$$ LANGUAGE plpgsql;
SELECT foo();

A implementation of ERROR_DETAIL and ERROR_HINT is simple and without
possible performance issues. It has zero impact on performance.

A implementation of ERROR_CONTEXT is not without impact on
performance, because context should be collected when exception is
caught. One solution is removing a ERROR_CONTEXT from proposal. Second
solution can be a design of enhanced syntax for exception trap like
(it means - collect CONTEXT when exception is handled)

BEGIN
EXCEPTION (ERROR_CONTEXT=true) WHEN OTHERS THEN
...
END

Getting a context can be a problem - but it is very important
information, that can significantly help with exception's explanation.

ideas, notes?

Regards

Pavel Stehule

Attachment Content-Type Size
getdiag.diff text/x-patch 5.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2011-05-21 20:09:12 SSI predicate locking on heap -- tuple or row?
Previous Message Heikki Linnakangas 2011-05-21 18:54:37 Re: Memory leak in FDW