Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key - Mailing list pgsql-bugs

From Matti Aarnio
Subject Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key
Date
Msg-id 5119871B.6040506@methics.fi
Whole thread Raw
In response to Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key  (Heikki Linnakangas <hlinnakangas@vmware.com>)
List pgsql-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 =3D e.getErrorCode();
>>        if (code =3D=3D 20000 // Derby
>>           || code =3D=3D 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 d=
river 8.4 and 8.2, and saw no difference; getErrorCode() always returned =
0.
>
> You should be using getSQLState() instead. The "23505" sqlstate is defi=
ned by the SQL standard, so if the other DBMS' you're supporting follow t=
he 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 getErro=
rCode() 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

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #7867: Similarity function fails
Next
From: Tony Kurz
Date:
Subject: Postgres 9.1 and 9.2 crashing with exit code 9