nextval skips values between consecutive calls - Mailing list pgsql-general

From
Subject nextval skips values between consecutive calls
Date
Msg-id 29F36C7C98AB09499B1A209D48EAA615BEF34B2487@mail2a.alliedtesting.com
Whole thread Raw
Responses Re: nextval skips values between consecutive calls  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I just found an odd thing about nextval (PostgreSQL 9.0): When nextval is called together with a function returning a
sequence,such as generate_series or unnest, it skips one value between consecutive calls: 

create sequence test_sequence;

-- This works as expected
select nextval(' test_sequence'); -- 1
select nextval(' test_sequence'); -- 2

-- This is rather surprising
select nextval(' test_sequence'), generate_series(1, 1); -- 3, 1
select nextval(' test_sequence'), generate_series(1, 1); -- 5, 1

drop sequence test_sequence;

Is there any explanation for why nextval skips a value in the second case?

By the way, if the second query is rewritten as follows, nextval again generates consecutive values:

select nextval(' test_sequence'), ind
from (select generate_series(1, 1) ind) A;

Is this a bug or a feature?


Dmitry Epstein | Developer

Allied Testing

www.alliedtesting.com
We Deliver Quality.


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: PostgreSQL Naming Rules
Next
From: Tom Lane
Date:
Subject: Re: nextval skips values between consecutive calls