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 1kn67W-0006OX-2k for pgsql-general@arkaria.postgresql.org; Wed, 09 Dec 2020 20:31:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kn67V-0004cy-1H for pgsql-general@arkaria.postgresql.org; Wed, 09 Dec 2020 20:31:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kn58h-0006gS-TE for pgsql-general@lists.postgresql.org; Wed, 09 Dec 2020 19:28:39 +0000 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kn58e-0002wb-F4 for pgsql-general@lists.postgresql.org; Wed, 09 Dec 2020 19:28:39 +0000 Received: by mail-qt1-x829.google.com with SMTP id a6so1810803qtw.6 for ; Wed, 09 Dec 2020 11:28:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=0sceV+hOFq6qWRvPFTijZsW/OZHI84DWnoEyjpuW7QY=; b=O2hQWmux12eI0KsTnitKjEovi+EzDkTPOrI/PE8yK/fyxtkqiqTUgoCjjFTq67zLxE QXJctn6W4KydKjSGnCmovTzTX63C/0veeh7inF1iJHRYL/2ZmFjUPHhrar6hqJB0Kser P09xF7v9slpU03sdV40dCJ0iFP+ANnxlPG+qPagFxm4d1s7i28JSMIkrZSxlOFEStd6w 6ovkrzXVVqs7vFEzlcymPxJfjVUPn0/O+VL7S2OeeJzluJ4juO/vzXQ3/GBkrgZYhFcO QXmPNUDHCXJCr9SbuurHIcXbGIMXWx2AaZiuI568J2Zot/S6UhQVHyG4/+OIFbAVIA7R v6lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=0sceV+hOFq6qWRvPFTijZsW/OZHI84DWnoEyjpuW7QY=; b=qkJv5oQuugLXH3QV/SredIvUeB+5rzaQgiyX6UcCqDMtNPW/iZDYQ+5oUZhG5qhhx4 O31XS5E4cEjz2IDc35g4p+Hw7sqOh6mKE+xkYUOThky0d4I1htHEcZNtfUt2HNpz6Nqs QT57stOX5uN6QJcqqKj82RrHmWcc2+neJ0fwOj0HBwwuv/eLPFVE8uCVZqR1G5KcU9zf LbyzEsSJ3K/1bwCw9XfqEqaGHg3GUNdfMXIPlPlBnh9lgghWkmOlOAsUvFUMxjlPbqMr 53N609XvhnRCIrcdKIDaajUaOWj9SoZciYoCOLWJUaexD3mOmWTQKQWCQRabsvF4mYal bP3A== X-Gm-Message-State: AOAM533cuH9B+sizCl5mCHXGsG1GxTy/q73FcnvoFlNCAfE03VWjCY62 n6p6AGGGQldXpxlnHs2xCrsPpDSN2FE= X-Google-Smtp-Source: ABdhPJzCvOjqxhLNLJ25vgld1SaIUhYPsq7FpZa6qCvoNtlRmF02tnaVx6FkjJNEwSpDDi3scQ92dw== X-Received: by 2002:aed:2ac1:: with SMTP id t59mr4758425qtd.165.1607542114009; Wed, 09 Dec 2020 11:28:34 -0800 (PST) Received: from [192.168.50.211] ([104.163.190.166]) by smtp.gmail.com with ESMTPSA id 84sm1827737qkd.46.2020.12.09.11.28.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Dec 2020 11:28:32 -0800 (PST) Subject: Re: JDBC driver - is "getGeneratedKeys()" guaranteed to return the ids in the same order a batch insert was made? To: "pgsql-generallists.postgresql.org" References: <36689061-0844-2dfd-a4ee-8006d8a15ca9@gmail.com> <1d0c8b21-25cc-2a3e-7f25-81f2de645f1e@gmail.com> <4ce0f5f5-d608-887b-b5ef-21ae187e3b58@gmail.com> From: electrotype Message-ID: Date: Wed, 9 Dec 2020 14:28:29 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------55F4067ED6CB081C3461BB0D" 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. --------------55F4067ED6CB081C3461BB0D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Agreed. > > However, this isn't really the purview of JDBC - I'm doubting it does anything that would cause > the order to be different than what is received, and the batch items are sent and results > processed sequentially. > > The main question is whether any batch items are inserting multiple records themselves - i.e., > RETURNING * is producing multiple results.  Whatever order RETURNING * produces is what the driver > will capture - but it isn't responsible for guaranteeing that the order of multiple inserted > records going in matches what comes out.  PostgreSQL needs to make that claim.  I don't see where > it does (i've sent an email to see if adding such a claim to the documentation is proper).  Done > manually one can always do "WITH insert returning SELECT ORDER BY", but it doesn't seem workable > for the driver to try and do that when adding the returning clause, which I presume is what is in > scope here. > > David J. > Thank you, it's appreciated! I'm sure this clarification would help other developers too. --------------55F4067ED6CB081C3461BB0D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Agreed.

However, this isn't really the purview of JDBC - I'm doubting it does anything that would cause the order to be different than what is received, and the batch items are sent and results processed sequentially.

The main question is whether any batch items are inserting multiple records themselves - i.e., RETURNING * is producing multiple results.  Whatever order RETURNING * produces is what the driver will capture - but it isn't responsible for guaranteeing that the order of multiple inserted records going in matches what comes out.  PostgreSQL needs to make that claim.  I don't see where it does (i've sent an email to see if adding such a claim to the documentation is proper).  Done manually one can always do "WITH insert returning SELECT ORDER BY", but it doesn't seem workable for the driver to try and do that when adding the returning clause, which I presume is what is in scope here.

David J.

Thank you, it's appreciated! I'm sure this clarification would help other developers too.
--------------55F4067ED6CB081C3461BB0D--