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

SERIAL order and INSERT order

From: l1(at)nym(dot)hush(dot)com
To: pgsql-novice(at)postgresql(dot)org
Subject: SERIAL order and INSERT order
Date: 2011-06-14 18:30:36
Message-ID: 20110614183036.58B4314DBCF@smtp.hushmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
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?  

e.g. 
thread 1 does INSERT getting serial number 1
thread 2 does INSERT getting serial number 2

and both complete successfully (no rollbacks).

Are there any cases where an observer might see a row with serial 
number 2 but not yet see serial number 1, perhaps because thread 1 
hasn't completed its insert yet?  For example SELECT * WHERE 
seqnumber < 3; would return only a row with seqnumber=2?

thanks


Responses

pgsql-novice by date

Next:From: Merlin MoncureDate: 2011-06-14 19:11:44
Subject: Re: SERIAL order and INSERT order
Previous:From: Andreas KretschmerDate: 2011-06-14 13:43:35
Subject: Re: Passing the table name as a function argument inPLPGSQL

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