catching errors in function
catching errors in function
От:
"padmanabha konkodi" <konkodi221@rediffmail.com>
Дата:
hello sql developers,
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
plz help me
regards
konkodi
Re: catching errors in function
От:
"Eugene E." <sad@bankir.ru>
Дата:
> 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. BEGIN; SELECT you_function(args); ... many sql commands; ... COMMIT; that's all if your function raises an error whole transaction will be aborted when the COMMIT is called.
Re: catching errors in function
От:
John DeSoi <desoi@pgedit.com>
Дата:
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