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 51191894.4030703@methics.fi
Whole thread Raw
In response to Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key  (Matti Aarnio <matti.aarnio@methics.fi>)
List pgsql-bugs
On 02/11/2013 05:34 PM, Matti Aarnio wrote:
> On 02/11/2013 02:11 PM, Heikki Linnakangas wrote:
>> Works for me:
>>
>> postgres=3D# do $$
>> begin
>>   insert into example values ('2001-01-01', 'foo', 'bar');
>>   insert into example values ('2001-01-01', 'foo', 'bar');
>> exception
>>   when others then raise notice 'caught %', sqlstate;
>> end;
>> $$;
>> NOTICE:  caught 23505
>> DO
>>
>> How exactly are you seeing the wrong status code? What client are you
>> using?
> I am calling PostgreSQL JDBC driver through Tomcat 7 Pool manager..
> Which could of course scramble the status code report (unlikely, but
> possible..)
>
> The driver binary I was using is:  postgresql-9.0-801.jdbc3.jar
>
> Switching to jdbc4 driver binary of otherwise same version makes no
> difference.
> Neither switching to latest version makes any difference:=20
> postgresql-9.2-1002.jdbc4.jar


Catching the SQLException, and printing the backtrace shows:

2013-02-11 17:47:08,559 [http-bio-8080-exec-7] ERROR fi.methics.ExampleDa=
tabase - Insert into example at jdbc:kiuru:pool:example resulted unexpect=
ed SQL Exception code: 0 ERROR: duplicate key value violates unique const=
raint "replay_attack_detector_pkey"
  Detail: Key (a, b, c)=3D(a, b, 2013-02-11 17:47:08.163) already exists.=

org.postgresql.util.PSQLException: ERROR: duplicate key value violates un=
ique constraint "example_pkey"
  Detail: Key (a, b, c)=3D(a, b, 2013-02-11 17:47:08.163) already exists.=

        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(=
QueryExecutorImpl.java:2157)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryE=
xecutorImpl.java:1886)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutor=
Impl.java:255)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJd=
bc2Statement.java:555)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(A=
bstractJdbc2Statement.java:417)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(Abst=
ractJdbc2Statement.java:363)
        at sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth=
odAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport$St=
atementProxy.invoke(AbstractQueryReport.java:235)
        at $Proxy7.executeUpdate(Unknown Source)
        at fi.methics.ExampleDatabase.exampleInsert(ExampleDatabase.java:=
123)
=2E...

pgsql-bugs by date:

Previous
From: Matti Aarnio
Date:
Subject: Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key
Next
From: Tom Lane
Date:
Subject: Re: BUG #7867: Similarity function fails