Re: Sequence bug or feature?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "rob" <rob(at)cabrion(dot)com>
Cc: "pgsql-general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Sequence bug or feature?
Date: 2001-01-06 16:59:57
Message-ID: 17316.978800397@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"rob" <rob(at)cabrion(dot)com> writes:
> It appears that sequence.last_value and nextval('sequence') are out of sync
> when first created. My comments below are in [brackets]. Is this by design
> or is this a bug? Does this conform to SQL92? TIA.

It's by design. Note the is_called flag, which might be better named
ever_advanced or some such. The initial state is last_value = initial
value, is_called = false. The first nextval changes is_called to true;
subsequent ones increment last_value. So last_value is the last value
assigned only if a value has ever been assigned, ie, is_called is true.

This is a little bit baroque, agreed. I think the idea was to allow
sequences to start at MININT without creating arithmetic-overflow
issues.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message GH 2001-01-06 17:22:07 Re: PHP and PostgreSQL
Previous Message Tom Lane 2001-01-06 16:54:22 Re: Is libpq thread-safe?