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: Mon, 11 Feb 2013 17:34:30 +0200
Message-ID: <51190F86.9090102@methics.fi> (raw)
In-Reply-To: <5118DFDB.4080103@vmware.com>
References: <E1U4GzT-0005Q0-9a@wrigleys.postgresql.org>
	<5118DFDB.4080103@vmware.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 02/11/2013 02:11 PM, Heikki Linnakangas wrote:
> Works for me:
>
> postgres=# 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: 
postgresql-9.2-1002.jdbc4.jar


Java code:

  Connection conn = ...
  PreparedStatement ps = null;
  try {
     ps = conn.prepareStatement("INSERT INTO example(a,b,c)VALUES(?,?,?)");
     ps.setTimestamp(1, new Timestamp(1360596352000L));  // fixed value
for demo
     ps.setString(2, "x");
     ps.setString(3, "y");
     int rc = ps.executeUpdate();
     conn.commit();
     return true; // commit OK

  } 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());
     }
  } finally {
      try {
         if (ps != null)  ps.close();
      } catch (Exception e) { // ignore
      }
  }
  return false;


> - Heikki

Attachments:

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

view thread (7+ messages)  latest in thread

Message-ID: <51190F86.9090102@methics.fi>
Permalink:  ../51190F86.9090102@methics.fi/
Also on:    postgresql.org/message-id/51190F86.9090102@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: <51190F86.9090102@methics.fi>
  References: <E1U4GzT-0005Q0-9a@wrigleys.postgresql.org> <5118DFDB.4080103@vmware.com> <51190F86.9090102@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