Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

Next:From: Thomas KellererDate: 2011-06-15 07:21:48
Subject: Re: SERIAL order and INSERT order
Previous:From: l1Date: 2011-06-14 18:30:36
Subject: SERIAL order and INSERT order

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group