Re: Transactions, Triggers and Error Messages

Lists: pgsql-general
From: Ledina Hido <lh1101(at)ecs(dot)soton(dot)ac(dot)uk>
To: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Transactions, Triggers and Error Messages
Date: 2005-11-09 00:45:37
Message-ID: BEC2C039-9149-4027-9AA0-5FC7FDAE72C7@ecs.soton.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

That's great. Thank you very much for you help.

Ledina

On Tue, Nov 08, 2005 at 11:03:50PM +0000, Ledina Hido wrote:
> Quoting Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>
> > What are you running this in? ISTM this is a problem with bad
> structure
> > of client-side code, not something to be fixed on the server side.
> >
> > regards, tom lane
>
>
> I'm using pgAdmin3. Basically when I run the query the first time it
> gives the correct error but if I re-run it, then it says "ERROR:
> current transaction is aborted, commands ignored until end of
> transaction block". Should I be doing something else, ie should I be
> explicitly rolling back once the exception is raised so I don't get

Yes.

> this error? And if so how can I "catch" the exception. Sorry for my

http://lnk.nu/postgresql.org/5sl.html


From: Ledina Hido <lh1101(at)ecs(dot)soton(dot)ac(dot)uk>
To: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Transactions, Triggers and Error Messages
Date: 2005-11-09 00:57:56
Message-ID: 07C2E4F1-FAC8-4FD9-876B-8AC99CE4BC1B@ecs.soton.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


> On Tue, Nov 08, 2005 at 11:03:50PM +0000, Ledina Hido wrote:
> > Quoting Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> >
> > > What are you running this in? ISTM this is a problem with bad
> > structure
> > > of client-side code, not something to be fixed on the server side.
> > >
> > > regards, tom lane
> >
> >
> > I'm using pgAdmin3. Basically when I run the query the first time it
> > gives the correct error but if I re-run it, then it says "ERROR:
> > current transaction is aborted, commands ignored until end of
> > transaction block". Should I be doing something else, ie should I be
> > explicitly rolling back once the exception is raised so I don't get
>
> Yes.
>
> > this error? And if so how can I "catch" the exception. Sorry for my
>
> http://lnk.nu/postgresql.org/5sl.html

Thinking about it, the EXCEPTION statement would be inside my user-
defined function (where I raise the exception in the first place), so
I cannot see how that would help. As far as I could understand, I
cannot call "ROLLBACK" (which is what I want to do) inside a user
defined function. I tried calling it and it was simply ignored. Or am
I missing something here?


From: Richard Huxton <dev(at)archonet(dot)com>
To: Ledina Hido <lh1101(at)ecs(dot)soton(dot)ac(dot)uk>
Cc: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Transactions, Triggers and Error Messages
Date: 2005-11-09 07:31:01
Message-ID: 4371A5B5.9020909@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Ledina Hido wrote:
>
> Thinking about it, the EXCEPTION statement would be inside my user-
> defined function (where I raise the exception in the first place), so I
> cannot see how that would help. As far as I could understand, I cannot
> call "ROLLBACK" (which is what I want to do) inside a user defined
> function. I tried calling it and it was simply ignored. Or am I missing
> something here?

Yes - you want to read up on SAVEPOINTs to handle exceptions at the
applicaton level. You do something like:

SAVEPOINT foo;
...command that works...
...command that works...
...oops, this one gives me an error...
ROLLBACK TO SAVEPOINT foo;

Exceptions in plpgsql are just a wrapper to this process.

--
Richard Huxton
Archonet Ltd