Search Postgresql Archives

nextval skips values between consecutive calls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux