pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: electrotype <electrotype@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: JDBC driver - is "getGeneratedKeys()" guaranteed to return the ids in the same order a batch insert was made?
Date: Sun, 6 Dec 2020 15:51:51 -0500
Message-ID: <36689061-0844-2dfd-a4ee-8006d8a15ca9@gmail.com> (raw)

Hi,

Using JDBC, I batch insert multiple rows (/"executeBatch()/"). I then use 
/'//getGeneratedKeys("id")/' to get the generated ids ("id" is a "/SERIAL PRIMARY KEY/" column).

My question: does the PostgreSQL JDBC driver /guarantees /that the order of the returned generated 
ids will be the same as the rows to insert have been specified, using "/addBatch()/"?


The best "answer" to that question I have found is https://stackoverflow.com/a/16119489/843699 , but 
it is not 100% clear.

Would it be possible to have an official answer on this?

Thanks in advance!

view thread (11+ messages)  latest in thread

Message-ID: <36689061-0844-2dfd-a4ee-8006d8a15ca9@gmail.com>
Permalink:  ../36689061-0844-2dfd-a4ee-8006d8a15ca9@gmail.com/
Also on:    postgresql.org/message-id/36689061-0844-2dfd-a4ee-8006d8a15ca9@gmail.com

 · 

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-general@postgresql.org
  Cc: electrotype@gmail.com
  Subject: Re: JDBC driver - is "getGeneratedKeys()" guaranteed to return the ids in the same order a batch insert was made?
  In-Reply-To: <36689061-0844-2dfd-a4ee-8006d8a15ca9@gmail.com>
  References: <36689061-0844-2dfd-a4ee-8006d8a15ca9@gmail.com>

* 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