title: Upsert (update+insert) in PostgreSQL via JDBC / JPA returning strange row-count
body: <p>I'm using an "upsert", and I need to know whether it has created a new row or not. 
  The SQL is of the form:</p>
  
  <pre><code>update mytable set col1='value1' where (col2='value2');
  insert into mytable select 'value1', 'value2' where not exists (select 1 from mytable where (col2='value2'));
  </code></pre>
  
  <p>If I run this in Postgres, it returns the count of affected rows for the 2nd statement. I.e. "1 row affected" if it does an insert, "0 rows affected" if it does an update. Which is what I'd expect.</p>
  
  <p>Howevere if I run this over JDBC+JPA using a javax.persistence.Query object, I get the opposite behaviour: it returns 1 if it does an update, and 0 for an insert.</p>
  
  <p>Is the Java behaviour reliable? 
  I.e. can I code against that, or is it liable to change with future releases of the driver jar?</p>
  
  <p>Is there a better way of writing the upsert so that I also get the information back about which operation it did?</p>
  
  <p>Version details: I'm using PostgreSQL 9.1, Java 6, and the JDBC driver jar is postgresql-9.1-901.jdbc4.jar</p>
  
  <p>Thank you for your help!</p>