Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1km10g-00006h-2I for pgsql-general@arkaria.postgresql.org; Sun, 06 Dec 2020 20:51:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1km10e-0002aw-Tn for pgsql-general@arkaria.postgresql.org; Sun, 06 Dec 2020 20:51:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1km10e-0002ap-Jd for pgsql-general@lists.postgresql.org; Sun, 06 Dec 2020 20:51:56 +0000 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1km10c-0004bg-Bz for pgsql-general@lists.postgresql.org; Sun, 06 Dec 2020 20:51:55 +0000 Received: by mail-qk1-x72c.google.com with SMTP id y18so10789480qki.11 for ; Sun, 06 Dec 2020 12:51:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=8XUQPEaKePGV+Fvd9X2qUgEQD7q0HPnb2HBmrgoqNZ4=; b=VFul7y7bIXC0BUmBc0/IWMCDwwAlaBS+Hu6NdeUgrfJjV4JGKLbp0RMikzeoaK37z5 zlML/3od9xpOmwkmBMmSvzhfULlOCB07U7LKr3rCEKY6Gw3wavz6h6R93igrN6ms2QW+ fcljLRZNAjcqmQ2qCcSot3ar034tkg4RA1Oog12DXenUWY1Npk55w8Ubuo6uIeYqdt+9 ve9xcpaizn9JsLmmH49Zuraei5lS7wH6PpTaqO1WAp1EnYmqiAI6y/0ZICanVtfCu9oc OxR0nzFaiN5kq6tBxx2IYKlMHw2bVeASLmo5d5OnEWLQ8UAPNWNywvjnAeVJv9vUGOdt AChg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=8XUQPEaKePGV+Fvd9X2qUgEQD7q0HPnb2HBmrgoqNZ4=; b=lP0XN4aSV2GWCZywGcvwyJxRqwxs4ndpSrpZLwb+Bop1Bno573uRrxkCHK+Fcsww4e wdXTNUiCVSYGhdyTTkdUuuPxMUXEtdv1nrI2C6VMG3z3KJxbTdnjXNxv1lMOkw1pfEpc irvucYYPh7Zlqams01SaaN5aW0yarApqsQKugPt+voUUW4xBtm4yQEnd+PugE9meWuPc ZYVSbhwCs2XwxPl4w9TtFrasvyNN6SQVbSPxgdj4AgHWve7Hl5mTiW40JjqLTzit06+S xsWUSL9QiOKWccckuPlpcbqUHR8niiEv6AWpZ3JxArrjPe4EQcIogdrChhqVotPQlISa ReaA== X-Gm-Message-State: AOAM530+8VQMHuuVsLADb4WqSVQn0aH+vYwowaeoyaLluFVvNpXow6qp o1ifLOM/KKdANM81r/DLu9zHAtg5JcI= X-Google-Smtp-Source: ABdhPJzDGUCbor7VSCG4I5nzEyTnbTZ9Pi2mo9bGHLvUHqXHVwnE3WuNRvXYkcRH73KjTWuYDTo2Tw== X-Received: by 2002:a05:620a:1f3:: with SMTP id x19mr17180288qkn.17.1607287913155; Sun, 06 Dec 2020 12:51:53 -0800 (PST) Received: from [192.168.50.211] ([104.163.190.166]) by smtp.gmail.com with ESMTPSA id y192sm11389543qkb.12.2020.12.06.12.51.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Dec 2020 12:51:52 -0800 (PST) To: pgsql-general@lists.postgresql.org From: electrotype Subject: JDBC driver - is "getGeneratedKeys()" guaranteed to return the ids in the same order a batch insert was made? Message-ID: <36689061-0844-2dfd-a4ee-8006d8a15ca9@gmail.com> Date: Sun, 6 Dec 2020 15:51:51 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------6B9D448C8C7EDF59A4FDCE0C" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------6B9D448C8C7EDF59A4FDCE0C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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! --------------6B9D448C8C7EDF59A4FDCE0C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

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!


--------------6B9D448C8C7EDF59A4FDCE0C--