pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Grant <grant@conprojan.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: Sequence behaviour.
Date: Tue, 19 Jun 2001 02:09:53 -0400
Message-ID: <21972.992930993@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.21.0106191506230.8263-100000@webster.conprojan.com.au>
References: <Pine.LNX.4.21.0106191506230.8263-100000@webster.conprojan.com.au>

Grant <grant@conprojan.com.au> writes:
> Why is the following like it is? I would think that nextval would return 2
> in both instances, am I missing something here? :) Thanks!

> binary_data=# create sequence test;
> CREATE
> binary_data=# select nextval('test');
> NOTICE:  test.nextval: sequence was re-created

Um, how did you get that NOTICE?  I don't see it.

Anyway, the answer to your question is that there's another bit of
state in a sequence: the is_called flag is initially false and is
set true during the first-ever nextval().  This allows nextval to
deliver the specified start value on the first call, rather than
the one after that.  In 7.1 setval() takes an optional third
argument to reset the value of is_called...

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <21972.992930993@sss.pgh.pa.us>
Permalink:  ../21972.992930993@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21972.992930993@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, grant@conprojan.com.au
  Subject: Re: Sequence behaviour.
  In-Reply-To: <21972.992930993@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox