From: | Dave Cramer <davecramer(at)postgres(dot)rocks> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | electrotype <electrotype(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: JDBC driver - is "getGeneratedKeys()" guaranteed to return the ids in the same order a batch insert was made? |
Date: | 2020-12-11 11:01:01 |
Message-ID: | CADK3HHKHYFxHucSuThrVngdDFaZRUpTK0jo-H-ifZM+UEDPaMg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 10 Dec 2020 at 19:37, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
wrote:
> On Wed, Dec 9, 2020 at 1:31 PM electrotype <electrotype(at)gmail(dot)com> wrote:
>
>> 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.
>>
>
> My take is that there is presently no guarantee, and that with current
> efforts to add parallelism it is quite probable that observation of such
> non-orderedness is simply a matter of time. With batching it seems best to
> combine its use with single inserts in order to avoid this problem.
>
> David J.
>
I'd have to agree.
Dave Cramer
www.postgres.rocks
From | Date | Subject | |
---|---|---|---|
Next Message | Stephen Frost | 2020-12-11 14:30:03 | Re: "Required checkpoints occurs too frequently" |
Previous Message | Peter J. Holzer | 2020-12-11 09:30:42 | Re: Set COLLATE on a session level |