Re: Problems with sequences - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Problems with sequences
Date
Msg-id 4500196B.3040706@magproductions.nl
Whole thread Raw
In response to Re: Problems with sequences  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Martijn van Oosterhout wrote:
> On Thu, Sep 07, 2006 at 07:15:43AM -0400, Arturo Perez wrote:
>> iht=> select max(article_id) from article;
>> max
>> ------
>> 4992
>> (1 row)
>>
>> iht=> select nextval('pk_article');
>> nextval
>> ---------
>>     4986
>> (1 row)
>>
>> Assuming the sequence number is being used correctly why would they
>> be 6 apart?
>
> The last four transactions could be rolled back, or not committed yet.

Could you elaborate on that? I'm confused...

AFAIK after the sequence was initialised at max(article_id),
nextval(article_id) could never return a number that's lower than
max(article_id).

Unless:
   a) the OP managed to query max(article_id) and nextval(article_id)
from different transactions, the one querying nextval being older than
the one querying max.
   b) the OP inserted numbers not coming from the sequence; he shot his
own feet.
   c) the sequence wrapped around due to reaching numbers exceeding 2^32.

Or are you short on caffeine perhaps? ;)

Regards,
--
Alban Hertroys
alban@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
    7500 AK Enschede

// Integrate Your World //

pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: Majordomo drops multi-line Subject:
Next
From: "Joshua D. Drake"
Date:
Subject: Re: Majordomo drops multi-line Subject: