Re: catching errors in function - Mailing list pgsql-sql

From John DeSoi
Subject Re: catching errors in function
Date
Msg-id 36747E9C-455C-4C74-A49F-46AEFB12118D@pgedit.com
Whole thread Raw
In response to catching errors in function  ("padmanabha konkodi" <konkodi221@rediffmail.com>)
List pgsql-sql
On Oct 6, 2005, at 2:55 AM, padmanabha konkodi wrote:

> i have written function in which while executing it may throw error.
> if the error thrown i want rollback the transaction if not i want  
> commit.
>
> how can i achive this task.
>
> how can catch exception thrown in the function


The function itself cannot start or rollback a transaction (functions  
are always executed in the context of a transaction). But I think you  
can use a SAVEPOINT to accomplish your request:

http://www.postgresql.org/docs/8.0/interactive/sql-savepoint.html

And see this page on how to catch exceptions:

http://www.postgresql.org/docs/8.0/interactive/plpgsql-control- 
structures.html#PLPGSQL-ERROR-TRAPPING


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Scripting GRANT on functions
Next
From: "Dmitri Bichko"
Date:
Subject: UNION index use help