Unix Technical Forum

exception handling in plpgsql

This is a discussion on exception handling in plpgsql within the pgsql Hackers forums, part of the PostgreSQL category; --> hello I am using the following sytex to handle exceptions in plpgsql (I am using postgres 8 rc1) .....some ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 03:10 AM
Sibtay Abbas
 
Posts: n/a
Default exception handling in plpgsql

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

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 03:10 AM
Andrew Dunstan
 
Posts: n/a
Default Re: exception handling in plpgsql


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...-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?
>
>
>
>
>


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 03:10 AM
Michael Fuhr
 
Posts: n/a
Default Re: exception handling in plpgsql

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...-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...-appendix.html

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

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 03:10 AM
Andrew Dunstan
 
Posts: n/a
Default Re: exception handling in plpgsql



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...-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...-appendix.html
>
>



You are right. My humble apologies.

andrew

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 03:11 AM
Korry
 
Posts: n/a
Default Re: exception handling in plpgsql

> 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-11-2008, 03:11 AM
Michael Fuhr
 
Posts: n/a
Default Re: exception handling in plpgsql

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/

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-11-2008, 03:11 AM
Tom Lane
 
Posts: n/a
Default Re: exception handling in plpgsql

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.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-11-2008, 03:11 AM
Korry
 
Posts: n/a
Default Re: exception handling in plpgsql

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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:03 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com