Unix Technical Forum

Exception handling

This is a discussion on Exception handling within the Pgsql General forums, part of the PostgreSQL category; --> Can someone explain me about the exception handling in postgresql. Iam not understanding the scope of a exception block. ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-05-2008, 06:17 AM
sam
 
Posts: n/a
Default Exception handling

Can someone explain me about the exception handling in postgresql. Iam
not understanding the scope of a exception block. The exact confusion
that iam facing is as follows:
I have a procedure as follows
BEGIN
EXECUTE an update statement

EXECUTE an insert statement
EXCEPTION WHEN integrity_conatraint_violation THEN
RAISE NOTICE
END;

This procedure is called within another procedure. Now when an
exception is caught the updates are also getting rolled back. I need
the exception block to work only for the insert statement. But if i
dont write the exception block the whole program stops.
Any suggestions?

Thanks
Sam
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-05-2008, 06:17 AM
Stephan Szabo
 
Posts: n/a
Default Re: Exception handling

On Wed, 4 Jun 2008, sam wrote:

> Can someone explain me about the exception handling in postgresql. Iam
> not understanding the scope of a exception block. The exact confusion
> that iam facing is as follows:
> I have a procedure as follows
> BEGIN
> EXECUTE an update statement
>
> EXECUTE an insert statement
> EXCEPTION WHEN integrity_conatraint_violation THEN
> RAISE NOTICE
> END;
>
> This procedure is called within another procedure. Now when an
> exception is caught the updates are also getting rolled back. I need
> the exception block to work only for the insert statement. But if i
> dont write the exception block the whole program stops.
> Any suggestions?


I think you're looking for something like:

BEGIN
EXECUTE an update
BEGIN
EXECUTE an insert
EXCEPTION WHEN ...
RAISE NOTICE ...
END;
END;

The exception when is effectively associated with the block.



--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

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:35 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