pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matti Aarnio <matti.aarnio@methics.fi>
To: Heikki Linnakangas <hlinnakangas@vmware.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key
Date: Tue, 12 Feb 2013 02:04:43 +0200
Message-ID: <5119871B.6040506@methics.fi> (raw)
In-Reply-To: <51192FF9.3090504@vmware.com>
References: <E1U4GzT-0005Q0-9a@wrigleys.postgresql.org>
	<5118DFDB.4080103@vmware.com>
	<51190F86.9090102@methics.fi>
	<51192FF9.3090504@vmware.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 02/11/2013 07:52 PM, Heikki Linnakangas wrote:
> 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.

Indeed..
Going over my codebase I see that this was the only one where the getErrorCode() was used in place of getSQLState().
It worked just fine, but was noisy in the logs, thus this bugreport.

[x] User error.

> - Heikki

BR, Matti Aarnio

Attachments:

  smime.p7s (application/pkcs7-signature, 1.8K) download

view thread (7+ messages)

Message-ID: <5119871B.6040506@methics.fi>
Permalink:  ../5119871B.6040506@methics.fi/
Also on:    postgresql.org/message-id/5119871B.6040506@methics.fi

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: matti.aarnio@methics.fi, hlinnakangas@vmware.com
  Subject: Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key
  In-Reply-To: <5119871B.6040506@methics.fi>
  References: <E1U4GzT-0005Q0-9a@wrigleys.postgresql.org> <5118DFDB.4080103@vmware.com> <51190F86.9090102@methics.fi> <51192FF9.3090504@vmware.com> <5119871B.6040506@methics.fi>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox