Re: SQL error

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: x asasaxax <xanaruto(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL error
Date: 2008-04-19 15:17:05
Message-ID: 480A0CF1.6010602@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

  • SQL error at 2008-04-19 14:47:19 from x asasaxax

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-04-19 15:44:16 Re: Initial ugly reverse-translator
Previous Message Craig Ringer 2008-04-19 15:08:06 Re: SQL error