exception handling in plpgsql

Поиск
Список
Период
Сортировка
Искать

exception handling in plpgsql

От:
Sibtay Abbas <sibtay_abbas@yahoo.com>
Дата:
hello

I am using the following sytex to handle exceptions in
plpgsql (I am using postgres 8 rc1)

....some code ........

EXCEPTION   WHEN NO_DATA THEN        	RAISE NOTICE 'NO DATA';   WHEN OTHERS THEN       RAISE NOTICE 'An exception occurred';       RETURN emp_rec;

and i receive the following error 
ERROR:  unrecognized exception condition "no_data"

How can i rectify this error?

	
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250

Re: exception handling in plpgsql

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:

PEBKAC.

It has told you what the problem is. Use a handler for an exception that 
actually exists. To see what these are, read 
http://developer.postgresql.org/docs/postgres/plpgsql-errors-and-messages.html

cheers

andrew

Sibtay Abbas wrote:

>hello
>
>I am using the following sytex to handle exceptions in
>plpgsql (I am using postgres 8 rc1)
>
>....some code ........
>
>EXCEPTION
>    WHEN NO_DATA THEN      
>   	RAISE NOTICE 'NO DATA';
>    WHEN OTHERS THEN
>        RAISE NOTICE 'An exception occurred';
>        RETURN emp_rec;
>
>and i receive the following error 
>ERROR:  unrecognized exception condition "no_data"
>
>How can i rectify this error?
>
>
>	
>  
>

Re: exception handling in plpgsql

От:
Michael Fuhr <mike@fuhr.org>
Дата:
On Fri, Dec 31, 2004 at 03:18:39PM -0500, Andrew Dunstan wrote:

> It has told you what the problem is. Use a handler for an exception that 
> actually exists. To see what these are, read 
> http://developer.postgresql.org/docs/postgres/plpgsql-errors-and-messages.html

As the PL/pgSQL "Trapping Errors" documentation says, "The _condition_
names can be any of those shown in Appendix A," so a more useful link
would be:

http://developer.postgresql.org/docs/postgres/errcodes-appendix.html

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Re: exception handling in plpgsql

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:


Michael Fuhr wrote:

>On Fri, Dec 31, 2004 at 03:18:39PM -0500, Andrew Dunstan wrote:
>
>  
>
>>It has told you what the problem is. Use a handler for an exception that 
>>actually exists. To see what these are, read 
>>http://developer.postgresql.org/docs/postgres/plpgsql-errors-and-messages.html
>>    
>>
>
>As the PL/pgSQL "Trapping Errors" documentation says, "The _condition_
>names can be any of those shown in Appendix A," so a more useful link
>would be:
>
>http://developer.postgresql.org/docs/postgres/errcodes-appendix.html
>  
>


You are right. My humble apologies.

andrew

Re: exception handling in plpgsql

От:
Korry <korry@starband.net>
Дата:
I am using the following sytex to handle exceptions in
plpgsql (I am using postgres 8 rc1)

....some code ........

EXCEPTION
    WHEN NO_DATA THEN      
   	RAISE NOTICE 'NO DATA';
    WHEN OTHERS THEN
        RAISE NOTICE 'An exception occurred';
        RETURN emp_rec;

and i receive the following error 
ERROR:  unrecognized exception condition "no_data"

How can i rectify this error?

It seems you can’t trap every condition listed in errocodes-appendix.html; in particular, you can’t trap SUCCESSFUL_COMPLETION, any of the conditions listed in the WARNING category, or any of the conditions listed in the NO DATA category.  (At least through 8.0 rc1 - I haven't checked in later versions).

        -- Korry

Re: exception handling in plpgsql

От:
Michael Fuhr <mike@fuhr.org>
Дата:
On Sat, Jan 01, 2005 at 10:04:57AM -0500, Korry wrote:

> It seems you can???t trap every condition listed in errocodes-
> appendix.html; in particular, you can't trap SUCCESSFUL_COMPLETION, any
> of the conditions listed in the WARNING category, or any of the
> conditions listed in the NO DATA category.  (At least through 8.0 rc1 -
> I haven't checked in later versions).

src/pl/plpgsql/src/plerrcodes.h contains the following comment:

/* Success and warnings can't be caught, so omit them from table */

Maybe an IF NOT FOUND test could substitute for trapping NO DATA.
As for SUCCESSFUL COMPLETION, it seems reasonable to infer that the
operation was successful if an exception *isn't* raised (for some
definition of "successful" -- additional logic might be necessary).
Or maybe I'm misunderstanding the purpose of trapping these conditions.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Re: exception handling in plpgsql

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Korry  writes:
> It seems you can’t trap every condition listed in errocodes-
> appendix.html; in particular, you can’t trap SUCCESSFUL_COMPLETION, any
> of the conditions listed in the WARNING category, or any of the
> conditions listed in the NO DATA category.  (At least through 8.0 rc1 -
> I haven't checked in later versions).

Those aren't errors.
		regards, tom lane

Re: exception handling in plpgsql

От:
Korry <korry@starband.net>
Дата:
 On Sat, 2005-01-01 at 14:10 -0500, Tom Lane wrote: 
Korry <korry@starband.net> writes:
> It seems you can’t trap every condition listed in errocodes-
> appendix.html; in particular, you can’t trap SUCCESSFUL_COMPLETION, any
> of the conditions listed in the WARNING category, or any of the
> conditions listed in the NO DATA category.  (At least through 8.0 rc1 -
> I haven't checked in later versions).

Those aren't errors.

Right.  Just trying to clarify the issue for the person that asked the question. 

The pl/pgSQL documentation (37.7.5) says:

> The condition names can be any of those shown in Appendix A.

As you say, not all of the conditions listed in Appendix A are error conditions.  Perhaps 37.7.5 should be changed to clarify?  Without looking at plerrcodes.h, you can't find a definitive list.


        -- Korry

FAQ