2014-05-23 41 views
0

這裏我試圖顯示一個錯誤消息,當關系不存在時發生異常。PostgreSQL:關係不存在時例外

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:無法識別的異常狀態 「does_not_exist」

回答

3

您可以使用「undefined_table」處理。

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