proposal: enhanced get diagnostics statement - Mailing list pgsql-hackers

From Pavel Stehule
Subject proposal: enhanced get diagnostics statement
Date
Msg-id BANLkTikcOxJRB0HvKakHOJsJS3kgf4p6sg@mail.gmail.com
Whole thread Raw
Responses Re: proposal: enhanced get diagnostics statement  (Alvaro Herrera <alvherre@commandprompt.com>)
List 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

pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Memory leak in FDW
Next
From: "Kevin Grittner"
Date:
Subject: SSI predicate locking on heap -- tuple or row?