Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aX8tT-0007Ab-1s for pgsql-jdbc@arkaria.postgresql.org; Sat, 20 Feb 2016 14:52:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aX8tR-0007FK-M5 for pgsql-jdbc@arkaria.postgresql.org; Sat, 20 Feb 2016 14:52:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aX8tR-0007FD-8M for pgsql-jdbc@postgresql.org; Sat, 20 Feb 2016 14:52:21 +0000 Received: from plane.gmane.org ([80.91.229.3]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aX8tN-0001MS-0T for pgsql-jdbc@postgresql.org; Sat, 20 Feb 2016 14:52:20 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aX8tI-0002Hs-H1 for pgsql-jdbc@postgresql.org; Sat, 20 Feb 2016 15:52:12 +0100 Received: from ppp-46-244-205-114.dynamic.mnet-online.de ([46.244.205.114]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 20 Feb 2016 15:52:12 +0100 Received: from spam_eater by ppp-46-244-205-114.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 20 Feb 2016 15:52:12 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: JDBC behaviour Date: Sat, 20 Feb 2016 15:51:58 +0100 Lines: 90 Message-ID: References: <954cc530fdaf2c5cf63dcb180d05fb56@imap.procolix.com> <4C508581-9CA3-490D-A376-CC1F9FF5D258@me.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ppp-46-244-205-114.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Craig Ringer schrieb am 20.02.2016 um 11:44: > Please provide a complete, compileable, self-contained example demonstrating behaviour that >causes a failure or problem in PgJDBC but works correctly with at least most of: > > - MS SQL > - Oracle > - DB2 > - Sybase > - MySQL > > including test run output demonstrating the details of what exactly the behaviour of each other implementation is. Disclaimer: I do agree with you that Postgres behaviour is correct. A transaction either succeeds completely or not at all. Having said that: Postgres' behaviour *is* unique regarding this. Consider the following table: create table x (id integer not null primary key); The following code will run with Oracle, DB2, SQL Sever, MySQL and Firebird: ---- code start ---- public class TestInsert { public static void main(String args[]) throws Exception { Connection con = DriverManager.getConnection("...", "...", "..."); con.setAutoCommit(false); PreparedStatement pstmt = con.prepareStatement("insert into x (id) values (?)"); pstmt.setInt(1, 1); pstmt.executeUpdate(); try { pstmt.setInt(1, 1); pstmt.executeUpdate(); } catch (Exception ex) { System.out.println("***** Error: " + ex.getMessage()); } System.out.println("trying second row"); pstmt.setInt(1, 2); pstmt.executeUpdate(); con.commit(); ResultSet rs = con.createStatement().executeQuery("select count(*) from x"); if (rs.next()) { int rows = rs.getInt(1); System.out.println("rows: " + rows); } con.close(); } } ---- code end ---- With Oracle DB2, SQL Server, MySQL and Firebird you'll get something like this (this is from Oracle, the error message will of course differ for the others) ***** Error: ORA-00001: Unique Constraint (THOMAS.SYS_C0021623) violated trying second row rows: 2 With Postgres you get: ***** Error: ERROR: duplicate key value violates unique constraint "x_pkey" Detail: Key (id)=(1) already exists. trying second row Exception in thread "main" org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block But again: in contrast to the OP I do not consider this a bug, it's just that Postgres behaves differently. But I understand that it can be a problem when migrating applications that have a sloppy way of dealing with transactions. I was part in the migration of several projects from Oracle and MySQL to Postgres in the last two years, none of them had problems regarding that. Thomas -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc