pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Sequence behaviour.
3+ messages / 2 participants
[nested] [flat]

* Sequence behaviour.
@ 2001-06-19 05:12 Grant <grant@conprojan.com.au>
  2001-06-19 06:09 ` Re: Sequence behaviour. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Grant @ 2001-06-19 05:12 UTC (permalink / raw)
  To: pgsql-sql

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
 nextval
---------
       1
(1 row)

binary_data=# select setval('test', 1);
 setval
--------
      1
(1 row)

binary_data=# select nextval('test');
 nextval
---------
       2
(1 row)

binary_data=#




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Sequence behaviour.
  2001-06-19 05:12 Sequence behaviour. Grant <grant@conprojan.com.au>
@ 2001-06-19 06:09 ` Tom Lane <tgl@sss.pgh.pa.us>
  2001-06-19 23:04   ` Re: Sequence behaviour. Grant <grant@conprojan.com.au>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2001-06-19 06:09 UTC (permalink / raw)
  To: Grant <grant@conprojan.com.au>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Sequence behaviour.
  2001-06-19 05:12 Sequence behaviour. Grant <grant@conprojan.com.au>
  2001-06-19 06:09 ` Re: Sequence behaviour. Tom Lane <tgl@sss.pgh.pa.us>
@ 2001-06-19 23:04   ` Grant <grant@conprojan.com.au>
  0 siblings, 0 replies; 3+ messages in thread

From: Grant @ 2001-06-19 23:04 UTC (permalink / raw)
  To: pgsql-sql

> > 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.

This is version 7.0.3. I deleted the sequence first.

> 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...

Ok. Still a bit weird to me anyhow.

Thanks.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-06-19 23:04 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-19 05:12 Sequence behaviour. Grant <grant@conprojan.com.au>
2001-06-19 06:09 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-06-19 23:04   ` Grant <grant@conprojan.com.au>

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