1

Here I am trying to display a error message when relation does not exist then exception occurred.

Example:

Create or replace function fun_test() returns void as
$$ 
Begin
     Truncate testtb;
     Exception 
     When does_not_exist then /* When testtb does not exist*/
          raise info 'Relation does not exists';
     ...

ERROR: unrecognized exception condition "does_not_exist"

2 Answers 2

7

The condition "does_not_exist" does not exist. Refer to http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html

For testing use code like this ...

EXCEPTION
  WHEN others THEN
    RAISE NOTICE '%; SQLSTATE: %', SQLERRM, SQLSTATE; 

If you want to truncate more tables I suggest to use a function.

Sign up to request clarification or add additional context in comments.

Comments

6

You can handle with "undefined_table".

EXCEPTION WHEN undefined_table THEN
     RAISE NOTICE '%; SQLSTATE: %', SQLERRM, SQLSTATE; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.