Re: Sequence behaviour.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Grant <grant(at)conprojan(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Sequence behaviour.
Date: 2001-06-19 06:09:53
Message-ID: 21972.992930993@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Grant <grant(at)conprojan(dot)com(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message D'Arcy J.M. Cain 2001-06-19 11:43:08 Re: How to build a TRIGGER in POSTGERSQL
Previous Message Grant 2001-06-19 05:12:51 Sequence behaviour.