pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
catching errors in  function
3+ messages / 3 participants
[nested] [flat]

* catching errors in  function
@ 2005-10-06 06:55 padmanabha konkodi <konkodi221@rediffmail.com>
  2005-10-06 07:11 ` Re: catching errors in  function Eugene E. <sad@bankir.ru>
  2005-10-06 13:51 ` Re: catching errors in  function John DeSoi <desoi@pgedit.com>
  0 siblings, 2 replies; 3+ messages in thread

From: padmanabha konkodi @ 2005-10-06 06:55 UTC (permalink / raw)
  To: pgsql-sql

  
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


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: catching errors in  function
  2005-10-06 06:55 catching errors in  function padmanabha konkodi <konkodi221@rediffmail.com>
@ 2005-10-06 07:11 ` Eugene E. <sad@bankir.ru>
  1 sibling, 0 replies; 3+ messages in thread

From: Eugene E. @ 2005-10-06 07:11 UTC (permalink / raw)
  To: padmanabha konkodi <konkodi221@rediffmail.com>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: catching errors in  function
  2005-10-06 06:55 catching errors in  function padmanabha konkodi <konkodi221@rediffmail.com>
@ 2005-10-06 13:51 ` John DeSoi <desoi@pgedit.com>
  1 sibling, 0 replies; 3+ messages in thread

From: John DeSoi @ 2005-10-06 13:51 UTC (permalink / raw)
  To: padmanabha konkodi <konkodi221@rediffmail.com>; +Cc: 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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-10-06 13:51 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-06 06:55 catching errors in  function padmanabha konkodi <konkodi221@rediffmail.com>
2005-10-06 07:11 ` Eugene E. <sad@bankir.ru>
2005-10-06 13:51 ` John DeSoi <desoi@pgedit.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox