Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U4xYw-0007Kv-4g for pgsql-bugs@arkaria.postgresql.org; Mon, 11 Feb 2013 17:53:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U4xYv-0008Ns-BW for pgsql-bugs@arkaria.postgresql.org; Mon, 11 Feb 2013 17:53:05 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U4xYu-0008Nm-Nn for pgsql-bugs@postgresql.org; Mon, 11 Feb 2013 17:53:04 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U4xYs-0000nO-3B for pgsql-bugs@postgresql.org; Mon, 11 Feb 2013 17:53:03 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id AFC4B28D6C; Mon, 11 Feb 2013 09:53:00 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id ADCA1B0641; Mon, 11 Feb 2013 09:53:00 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 2BD69C1548; Mon, 11 Feb 2013 09:53:00 -0800 (PST) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-2.vmware.com Received: from zcs-prod-ext-mta-2.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-2.vmware.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5QLfrEVG2Tcj; Mon, 11 Feb 2013 09:53:00 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 06646C1525; Mon, 11 Feb 2013 09:53:00 -0800 (PST) Received: from [192.168.1.90] (unknown [10.113.62.14]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA; Mon, 11 Feb 2013 09:52:59 -0800 (PST) Message-ID: <51192FF9.3090504@vmware.com> Date: Mon, 11 Feb 2013 19:52:57 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: Matti Aarnio CC: pgsql-bugs@postgresql.org Subject: Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key References: <5118DFDB.4080103@vmware.com> <51190F86.9090102@methics.fi> In-Reply-To: <51190F86.9090102@methics.fi> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 11.02.2013 17:34, Matti Aarnio wrote: > } catch (SQLException e) { > int code = e.getErrorCode(); > if (code == 20000 // Derby > || code == 23505) {// PostgreSQL, Oracle, ... > System.out.println("Expected SQL duplicate insert indication > status code: "+code) > } else { > System.out.println("Insert into example at "+this.jdbcUrl+ > " resulted unexpected SQL Exception code: "+ > code + " " + e.getMessage()); > } Hmm, looking at the PSQLException source code, I don't think the driver has ever set the vendor-specific error code that getErrorCode() returns. I tested the snippet you posted with server 8,4 and 9.2, and with jdbc driver 8.4 and 8.2, and saw no difference; getErrorCode() always returned 0. You should be using getSQLState() instead. The "23505" sqlstate is defined by the SQL standard, so if the other DBMS' you're supporting follow the spec on that, you won't even need any vendor-specific code there. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs