Re: SERIAL order and INSERT order

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: l1(at)nym(dot)hush(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: SERIAL order and INSERT order
Date: 2011-06-14 19:11:44
Message-ID: BANLkTikuJdtguDs8UiCgsAJMELB8dBu_-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, Jun 14, 2011 at 1:30 PM, <l1(at)nym(dot)hush(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Thomas Kellerer 2011-06-15 07:21:48 Re: SERIAL order and INSERT order
Previous Message l1 2011-06-14 18:30:36 SERIAL order and INSERT order