Re: Exception handling

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: sam <sam(dot)mahindrakar(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Exception handling
Date: 2008-06-04 18:44:10
Message-ID: 20080604113808.B75823@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rob Richardson 2008-06-04 19:32:42 Slow access to remote database
Previous Message sam 2008-06-04 18:32:13 Exception handling