X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C1D293A1ED5 for ; Fri, 14 Jan 2005 19:20:40 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05920-05 for ; Fri, 14 Jan 2005 19:20:09 +0000 (GMT) Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by svr1.postgresql.org (Postfix) with SMTP id 50D643A1D9B for ; Fri, 14 Jan 2005 19:19:12 +0000 (GMT) Received: (qmail 14698 invoked from network); 14 Jan 2005 19:18:39 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.36?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 14 Jan 2005 19:18:39 -0000 Message-ID: <41E81B33.2060208@fastcrypt.com> Date: Fri, 14 Jan 2005 14:19:15 -0500 From: Dave Cramer Reply-To: pg@fastcrypt.com Organization: Postgres International User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "j.random.programmer" Cc: Csaba Nagy , pgsql-jdbc@postgresql.org Subject: Re: Weird behavior in transaction handling (Possible bug ?) References: <20050114185115.37537.qmail@web14201.mail.yahoo.com> In-Reply-To: <20050114185115.37537.qmail@web14201.mail.yahoo.com> Content-Type: multipart/alternative; boundary="------------060606010802070609020709" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.059 tagged_above=0 required=5 tests=AWL, HTML_30_40, HTML_MESSAGE, HTML_TITLE_EMPTY X-Spam-Level: X-Archive-Number: 200501/128 X-Sequence-Number: 12008 This is a multi-part message in MIME format. --------------060606010802070609020709 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit j.random.programmer wrote: >Dave: > > > >>Actually, reviewing your original post. Yes the >> >> >commit fails > > >>silently. However the insert does not fail silently >> >> >and should throw > > >>an error! Do you check for errors here ? >> >> > >I was simple catching the exception but not rolling >back since >I presumed the rest of the transaction would succeed >(and >commit() didn't complain). It's only after playing >around that I >realized that the transaction was failing because of >the earlier >error. > > > >>So correct me if I'm wrong. >>even in psql you are getting no error message from >>the commit statement? >> >> > >Here's a psql session >----------------------------------------------- >g=# create table foo (id int primary key, words text); >g=# begin; >g=# insert into foo values (1, 'hello'); >g=# insert into foo values (1, 'hello'); >ERROR: duplicate key violates unique constraint >"foo_pkey" >g=# end; >COMMIT >g=# select * from foo; >+----+-------+ >| id | words | >+----+-------+ >+----+-------+ >(0 rows) >------------------------------------------------ > >Note, the first insert failed silently too. > > The first insert does not fail, it is the duplicate key of the second insert that is the error. >So yeah, this looks like a postgres database specific >thing. But postgres is *better* than that -- the above >behavior is expected from myql BUT NOT postgres, right >? > >So maybe, the database folks can do something about >this in version 8.0. Maybe you can also forward this >message >to the core postgres folks ? > > They read this and will probably not respond because they do not consider this an error. > > >>The driver can't possibly know when something is >>going to fail. >> >> > >It can, since it gets an error back from the database >and "knows" the internal postgresql behavior. > >Specifically and in the MEANTIME, why can't you do >the >follwing in the JDBC driver ? > >----------- JDBC driver code ------------------ > >boolean sawExceptionInConnection = false; >String errorMessageInConnection; >.... >if an error is thrown back from the database >then > sawExceptionInConnection = true; > /*the error message that was actually recieved saved >here*/ > errorMessageInConnection = > "ERROR: duplicate key violates unique constraint"; >.... >in the commit() method implementation > >if (sawExceptionInConnection) >throw new SQLException( > "postgres will not allow this commit() to succeed > since an error was recieved from the database. > The error = " + errorMessageInConnection); > >---------------------------------------------- >Is there any technical reason why the above >cannot/should not >be implemented ? It would be the RIGHT thing to do >since >it would get rid of SILENT failure (which is >absolutely, utterly >wrong in any database). > > This is not a silent failure. The insert errored out and gave you a message. commit is basically just end transaction here. The user is supposed to handle the errors, not the driver. Dave >Best regards, > >--j > > > > >__________________________________ >Do you Yahoo!? >The all-new My Yahoo! - What will yours do? >http://my.yahoo.com > > > > -- Dave Cramer http://www.postgresintl.com 519 939 0336 ICQ#14675561 --------------060606010802070609020709 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit

j.random.programmer wrote:
Dave:

  
Actually, reviewing your original post. Yes the
    
commit fails 
  
silently. However the insert does not fail silently
    
and should throw 
  
an error! Do you check for errors here ?
    

I was simple catching the exception but not rolling
back since
I presumed the rest of the transaction would succeed
(and
commit() didn't complain). It's only after playing
around that I
realized that the transaction was failing because of
the earlier
error.

  
So correct me if I'm wrong.
even in psql you are getting no error message from
the commit statement?
    

Here's a psql session
-----------------------------------------------
g=# create table foo (id int primary key, words text);
g=# begin;
g=# insert into foo values (1, 'hello');
g=# insert into foo values (1, 'hello');
ERROR:  duplicate key violates unique constraint
"foo_pkey"
g=# end;       
COMMIT
g=# select * from foo;
+----+-------+
| id | words |
+----+-------+
+----+-------+
(0 rows)
------------------------------------------------

Note, the first insert failed silently too.
  
The first insert does not fail, it is the duplicate key of the second insert that is the error.
So yeah, this looks like a postgres database specific
thing. But postgres is *better* than that -- the above
behavior is expected from myql BUT NOT postgres, right
?

So maybe, the database folks can do something about
this in version 8.0. Maybe you can also forward this
message
to the core postgres folks ?
  
They read this and will probably not respond because they do not consider this an error.
  
The driver can't possibly know when something is
going to fail.
    

It can, since it gets an error back from the database
and "knows" the internal postgresql behavior. 

Specifically and in the MEANTIME,  why can't you do
the 
follwing in the JDBC driver ?

-----------  JDBC driver code ------------------

boolean sawExceptionInConnection = false;
String  errorMessageInConnection;
....
if an error is thrown back from the database
then 
 sawExceptionInConnection = true;
 /*the error message that was actually recieved saved
here*/
 errorMessageInConnection = 
   "ERROR:  duplicate key violates unique constraint";
....
in the commit() method implementation

if (sawExceptionInConnection)
throw new SQLException(
	"postgres will not allow this commit() to succeed
	since an error was recieved from the database.
	The error = " + errorMessageInConnection);
	
----------------------------------------------			
Is there any technical reason why the above
cannot/should not
be implemented ? It would be the RIGHT thing to do
since
it would get rid of SILENT failure (which is
absolutely, utterly
wrong in any database). 
  
This is not a silent failure. The insert errored out and gave you a message. commit is basically just end transaction here.
The user is supposed to handle the errors, not the driver.

Dave
Best regards,

--j



		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 


  

-- 
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561
--------------060606010802070609020709--