Skip site navigation (1) Skip section navigation (2)

Rollback with functions

From: A B <gentosaker(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Rollback with functions
Date: 2010-01-22 12:40:49
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

I have yet not fully understood the magic with transactions in
combination with plpgsql functions.

Assume I have a function

create function foo()
       do stuff
       ....  <--- here it fails

and a call to the function fails (as indicated in the code), will
everything that  has been done inside the function be automatically
undone (rollbacked)?

If I had added code for exceptions, like this

create function foo()
       do stuff
   exception when others then
       ....  <--- clean up code

Then I would need the "clean up code", or else there would be some
changes in the database caused by all the commands that were actually
run before the failure, right?

So is there then any other reason besides having a way to tell exactly
what went wrong (which I understand is a good thing ), to have the
"clean up code"? (you might of course need to have more exception
statements and add exceptions to the clean up code, and so on...


pgsql-novice by date

Next:From: Tom LaneDate: 2010-01-22 16:06:03
Subject: Re: Rollback with functions
Previous:From: James William PyeDate: 2010-01-20 21:47:50
Subject: Re: [NOVICE] Python verison for build in (Win32)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group