Re: SQL error - Mailing list pgsql-general

From Craig Ringer
Subject Re: SQL error
Date
Msg-id 480A0CF1.6010602@postnewspapers.com.au
Whole thread Raw
In response to SQL error  ("x asasaxax" <xanaruto@gmail.com>)
List pgsql-general
x asasaxax wrote:
> HI everyone,
>
>
> I´m trying to capture all the possible errors that a statement can have.
> And, if there´s any error i will do a rollback; What i´m trying to do its:
> BEGIN
>   insert into temp values(1, 2, 3);
>   IF ANY_ERROR_OCCURED THEN
>      ROLLBACK;

Sorry, I didn't see the ROLLBACK statement there. Please disregard my
previous reply; I thought you were trying to do something other than
what you appear to be doing.

As Martijn van Oosterhout noted, the transaction will be put in an error
state that ignores further commands. When in an error state, the
transaction will treat COMMIT as ROLLBACK.

I assume you wish to attempt to do something and if it fails, abort the
transaction and leave everything in a working state ready for more
commands? If so, consider doing that at the application level rather
than trying to do it in SQL. All database interfaces give you a way to
find out if an error occurred and get some information about the error.

Maybe if you explained your end goal and why you're trying to do this it
might help people give you more useful answers?

--
Craig Ringer

pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: SQL error
Next
From: Tom Lane
Date:
Subject: Re: Initial ugly reverse-translator