Re: SERIAL order and INSERT order - Mailing list pgsql-novice

From Merlin Moncure
Subject Re: SERIAL order and INSERT order
Date
Msg-id BANLkTikuJdtguDs8UiCgsAJMELB8dBu_-Q@mail.gmail.com
Whole thread Raw
In response to SERIAL order and INSERT order  (l1@nym.hush.com)
List pgsql-novice
On Tue, Jun 14, 2011 at 1:30 PM,  <l1@nym.hush.com> wrote:
> Hi
>
> I have a table defined as follows:
>
> CREATE TABLE mytable (
>   seqnumber BIGSERIAL;
>   ...
> )
>
> and I have multiple threads inserting into the table.
>
> If multiple threads insert at the same time, will the sequence
> numbers generated always appear in the table in order?

It's going to depend on how you define 'order'.  I take it you mean
transaction commit order based on time.

sequence numbers are always *fetched* in order. however, if two
separate threads are grabbing numbers and inserting them roughly a the
same time, there could be a race to transaction commit (although I
wonder how that could possibly matter, since your app is multi
threaded and there is no distinguishing information outside of the
sequence value itself).

merlin

pgsql-novice by date:

Previous
From: l1@nym.hush.com
Date:
Subject: SERIAL order and INSERT order
Next
From: Thomas Kellerer
Date:
Subject: Re: SERIAL order and INSERT order