Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > PostgreSQL > postgres sequence

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-25-03, 13:41
sshriyan sshriyan is offline
Registered User
 
Join Date: May 2003
Location: Tampa, Florida
Posts: 13
postgres sequence

I'm using the sequence for table primary key and it increases by 1,
I have noticed sometimes the data get lost and the sequence get skipped, that means when ever I inserted a record say the seq was 10, the next one should be 11, instead it skips to 13 and I see 2 records has been missing.
What causes this problem Please let me know if anyone knows the answer to this question.
Reply With Quote
  #2 (permalink)  
Old 06-25-03, 16:20
rycamor rycamor is offline
Registered User
 
Join Date: May 2002
Location: Florida, USA
Posts: 49
Sequences are a one-way procedure. I believe that every time you attempt to insert a row that uses a sequence, that sequence is advanced, even if the INSERT fails.

This can be especially important in a heavy multi-user application, where many users may be trying to INSERT to a table at the same time. Thus if for some reason there is too much resource contention, a sequence may be advanced, although the INSERT fails.

Remember, sequences are independent of the table. Sequences can be advanced simply by calling SELECT nextval('squence_name');. Once advanced, they cannot be reversed. In fact, for this reason, a sequence can be shared among several tables, because every sequence call is atomic.

Sequences aren't for the purpose of keeping a perfect numerical progression, but for guaranteeing uniqueness.

So, your problem doesn't mean records are missing. It just means that the sequence has been advanced, but not used in the table.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On