error handling codes

From: "Sim Zacks" <sim(at)nospam(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: error handling codes
Date: 2005-02-20 09:34:17
Message-ID: cv9lm6$he6$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

PostGresQL 8 beta1.
PGAdmin III beta 1.21

Is there a way to see what error code or error message occured when an error
happens?
I am trying to perform exception handling and a create view that included
another view that did not exist occured in a plpgsql function.
I finally figured out that the error was Undefined_table, though that is
obviously not implicit.
The error I received was "relation "bob2" does not exist" There were no
error numbers or other indications that led me to the correct error code in
Appendix A of the documentation.
I could not find in the documentation if there is any functionality
available to the exception, such as exception.number, exception.message
etc.. Does duch a thing exist?

As an example here is the code I am testing. The view name was false on
purpose in this test so I could figure out how to handle it when I really
get a view that is wrong.

Thanks
Sim

create or replace function testexcept() returns void as
$$
begin
begin
create view dummy as
select * from dummy2;
exception
when UNDEFINED_TABLE then
raise notice 'its an undefined table';
when others then
raise notice 'it is not an undefined table';
end;
return;
end;
$$ language 'plpgsql'

Browse pgsql-general by date

  From Date Subject
Next Message Phil Endecott 2005-02-20 13:24:49 Scalability with large numbers of tables
Previous Message Sim Zacks 2005-02-20 06:30:47 Re: Newbie: PG8 and text file parsing