Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5J6A5a64968 for ; Tue, 19 Jun 2001 02:10:05 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f5J69s321975; Tue, 19 Jun 2001 02:09:54 -0400 (EDT) To: Grant cc: pgsql-sql@postgresql.org Subject: Re: Sequence behaviour. In-reply-to: References: Comments: In-reply-to Grant message dated "Tue, 19 Jun 2001 15:12:51 +1000" Date: Tue, 19 Jun 2001 02:09:53 -0400 Message-ID: <21972.992930993@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200106/284 X-Sequence-Number: 3547 Grant 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