Re: Sequence skipping values

From: Jean-Christophe Roux <jcxxr(at)yahoo(dot)com>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Sequence skipping values
Date: 2006-02-10 23:27:23
Message-ID: 20060210232723.78421.qmail@web35312.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
Thanks four your answers. Let me give more details here.
The table with the id not incrementing by 1 as I expected is named topics.

I have three other tables that contain rules that on insert into those
tables, some fields of the table Topic should be updated.
Each of those three tables contain a column that refer to topics.id as a
foreign key.
Those three columns contain id automatically generated by sequences and I
have not observed any problem

Thanks
JC

Steve Crawford <scrawford(at)pinpointresearch(dot)com> wrote: Jean-Christophe Roux wrote:
> Hello,
> I have a table with and id field (primary key) which default value is
> the result of a sequence (increment explicitly set to 1).
> To my surprise, the real increment on insert is the total number of rows
> of the table. For instance, with 41 rows and a sequence last_value of
> 1141, the next insert row will have a value of 1182. It is not a big
> problem but I don't like skipping and wasting values in a sequence.
> Also, I'd like to understand what's going on!
> If someone could give me a clue that wold be greatly appreciated
> thanks
> JC

Any rules, triggers, etc. involved? How are the inserts done (insert one
record into the table)? What relationships does the table have to any
other tables? Anything else accessing that sequence?

There is no guarantee that a sequence will be contiguous. For example,
begin...insert into...rollback will not reset the sequence as other
transactions could have incremented the sequence.

Cheers,
Steve


---------------------------------
Yahoo! Mail
Use Photomail to share photos without annoying attachments.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Crawford 2006-02-11 00:08:57 Re: Sequence skipping values
Previous Message Tino Wildenhain 2006-02-10 21:43:52 Re: Tool