Sequence bug or feature? - Mailing list pgsql-general

From rob
Subject Sequence bug or feature?
Date
Msg-id 000901c077eb$10339610$4100fd0a@cabrion.org
Whole thread Raw
In response to Disapointed !!  (François LODIER <zentak@agisphere.com>)
Responses Re: Sequence bug or feature?
List pgsql-general
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.

--rob


partner=> create SEQUENCE junk;
CREATE
partner=> select junk.last_value;
 last_value
------------
          1       [ last value is one  . . . Thought it would be 0, but
that's no big deal]
(1 row)

partner=> select nextval('junk');
 nextval
---------
       1        [If last value was one then why is nextval() not 2 ?!?!?]
(1 row)

partner=> select junk.last_value;
 last_value
------------
          1       [Consistent, but I expected 2 as described above]
(1 row)

partner=> select nextval('junk');
 nextval
---------
       2           [Ahhh now that's better]
(1 row)

partner=> select junk.last_value;
 last_value
------------
          2        [Just what I expected . . . ]
(1 row)



pgsql-general by date:

Previous
From: Mike Mascari
Date:
Subject: Is libpq thread-safe?
Next
From: Frank Joerdens
Date:
Subject: Re: PHP and PostgreSQL