| From: | <depstein(at)alliedtesting(dot)com> |
|---|---|
| To: | <pgsql-general(at)postgresql(dot)org> |
| Cc: | <pgagarinov(at)alliedtesting(dot)com> |
| Subject: | nextval skips values between consecutive calls |
| Date: | 2011-10-28 15:07:55 |
| Message-ID: | 29F36C7C98AB09499B1A209D48EAA615BEF34B2487@mail2a.alliedtesting.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2011-10-28 15:21:40 | Re: nextval skips values between consecutive calls |
| Previous Message | Adrian Klaver | 2011-10-28 14:27:50 | Re: PostgreSQL Naming Rules |