0

I'd like to have errors caught within a BEGIN/EXCEPTION/END block logged.

Here's what I have, compare 1. and 2.

-- 1. Nothing will be logged
CREATE OR REPLACE FUNCTION func()
  RETURNS VOID AS $$
BEGIN
  ...
  BEGIN
    RAISE EXCEPTION 'Why no logging of this occurrence?';
  EXCEPTION WHEN OTHERS THEN
    RAISE NOTICE 'Never mind, keep going mate';
  END;
  ...
END;
$$ LANGUAGE plpgsql;

-- 2. A log entry will be made but my function will terminate early
CREATE OR REPLACE FUNCTION func()
  RETURNS VOID AS $$
BEGIN
  ...
  RAISE EXCEPTION 'Why no logging of this occurrence?';
  ...
END;
$$ LANGUAGE plpgsql;

How do I get Postgresql to issue a log entry for 1.? I have a lot of IO occurring and I need to know where things went wrong. As a side note, a periodic function runs a number of jobs (sub functions calls) with each being likely to fail for external reasons, hence the BEGIN/EXCEPTION/END. However that period function itself never fails.

PS. I worded the question as such but perhaps this is just a side effect of some general parameter. I'm still exploring Postgresql at this stage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.