Logging in function with exception

From: Gerhard Heift <ml-postgresql-20081012-3518(at)gheift(dot)de>
To: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Logging in function with exception
Date: 2008-11-10 15:31:31
Message-ID: 20081110153130.GA11099@toaster.kawo1.rwth-aachen.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I write funktions in pl/pgsql and want to abort it. For this I use raise
exception, to undo all changes for this transaction. Now I want to log
these exceptions somewhere.

DECLARE
a integer;
log_id integer;
BEGIN
SELECT a INTO b FROM c WHERE d = 10;
IF NOT FOUND THEN
INSERT INTO log (logtype, logtext)
VALUES ('error', 'Dit not found 10 in table')
RETURNING id INTO log_id;
RAISE EXCEPTION 'internal_error: %', log_id;
END IF;
-- anything else
END;

I know that these logs well be discard, if the commit rolls back.

Is there a possible way to implement something like this?

Thanks,
Gerhard

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gerhard Heift 2008-11-10 15:33:13 Re: Get interval in months
Previous Message Tom Lane 2008-11-10 15:27:32 Re: LIKE, "=" and fixed-width character fields