Logging in function with exception - Mailing list pgsql-general

From Gerhard Heift
Subject Logging in function with exception
Date
Msg-id 20081110153130.GA11099@toaster.kawo1.rwth-aachen.de
Whole thread Raw
Responses Re: Logging in function with exception  ("Asko Oja" <ascoja@gmail.com>)
List 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

Attachment

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: LIKE, "=" and fixed-width character fields
Next
From: Gerhard Heift
Date:
Subject: Re: Get interval in months