Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Matti Aarnio <matti(dot)aarnio(at)methics(dot)fi>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key
Date: 2013-02-11 17:52:57
Message-ID: 51192FF9.3090504@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Matti Aarnio 2013-02-12 00:04:43 Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key
Previous Message Matti Aarnio 2013-02-11 16:13:08 Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key