Re: Shouldn't "aborted transaction" be an ERROR? (was Re:

From: Dave Cramer <Dave(at)micro-automation(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: John Taylor <postgres(at)jtresponse(dot)co(dot)uk>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Shouldn't "aborted transaction" be an ERROR? (was Re:
Date: 2002-06-13 14:44:46
Message-ID: 1023979494.1540.173.camel@inspiron.cramers
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-jdbc pgsql-novice

I have just tested this on the latest code using the following

Connection con = JDBC2Tests.openDB();
try
{

// transaction mode
con.setAutoCommit(false);
Statement stmt = con.createStatement();
stmt.execute("select 1/0");
fail( "Should not execute this, as a SQLException s/b thrown" );
con.commit();
}
catch ( Exception ex )
{
}
try
{
con.commit();
con.close();
}catch ( Exception ex) {}
}

and it executes as expected. It throws the SQLException and does not
execute the fail statement

Thanks,

Dave

On Wed, 2002-06-12 at 12:12, Tom Lane wrote:
> John Taylor <postgres(at)jtresponse(dot)co(dot)uk> writes:
> > On Wednesday 12 June 2002 16:36, Tom Lane wrote:
> >> Queries after the failure aren't run at all; they're only passed through
> >> the parser's grammar so it can look for a COMMIT or ROLLBACK command.
> >> Normal processing resumes after ROLLBACK. If you were paying attention
> >> to the return codes you'd notice complaints like
> >>
> >> regression=# begin;
> >> BEGIN
> >> regression=# select 1/0;
> >> ERROR: floating point exception! The last floating point operation either exceeded legal ranges or was a divide by zero
> >> -- subsequent queries will be rejected like so:
> >> regression=# select 1/0;
> >> WARNING: current transaction is aborted, queries ignored until end of transaction block
> >> *ABORT STATE*
>
> > Well, I'm using JDBC, and it isn't throwing any exceptions, so I
> > assumed it was working :-/
>
> This brings up a point that's bothered me in the past. Why is the
> "queries ignored" response treated as a NOTICE and not an ERROR?
> A client that is not paying close attention to the command result code
> (as JDBC is evidently not doing :-() might think that its command had
> been executed.
>
> It seems to me the right behavior is
>
> regression=# select 1/0;
> ERROR: current transaction is aborted, queries ignored until end of transaction block
> regression=#
>
> I think the reason why it's been done with a NOTICE is that if we
> elog(ERROR) on the first command of a query string, we'll not be able to
> process a ROLLBACK appearing later in the same string --- but that
> behavior does not seem nearly as helpful as throwing an error.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeroen T. Vermeulen 2002-06-13 14:54:24 Re: Integrating libpqxx
Previous Message Thomas Lockhart 2002-06-13 14:20:42 Re: New string functions; initdb required

Browse pgsql-jdbc by date

  From Date Subject
Next Message Paul Bethe 2002-06-13 16:11:47 New Patch For CallableStmt (against current CVS)
Previous Message Dave Cramer 2002-06-13 14:03:47 Re: Updateable result set

Browse pgsql-novice by date

  From Date Subject
Next Message Daniel Grob 2002-06-13 14:52:36 case-(in)sensitive Server
Previous Message Andrew McMillan 2002-06-13 12:46:05 Re: How efficient are Views