From: | Boszormenyi Zoltan <zb(at)cybertec(dot)at> |
---|---|
To: | Thomas Guettler <hv(at)tbz-pariv(dot)de> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Get block of N numbers from sequence |
Date: | 2009-05-19 16:38:10 |
Message-ID: | 4A12E072.6090204@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thomas Guettler írta:
> Hi,
>
> how can you get N numbers (without holes) from a sequence?
>
> Thomas
>
>
# create sequence tmp_seq cache 1000;
CREATE SEQUENCE
From the same client:
# select nextval('tmp_seq');
nextval
---------
1
(1 sor)
# select nextval('tmp_seq');
nextval
---------
2
(1 sor)
# select nextval('tmp_seq');
nextval
---------
3
(1 sor)
# select nextval('tmp_seq');
nextval
---------
4
(1 sor)
... (ad nauseum)
From another psql client:
# select nextval('tmp_seq');
nextval
---------
1001
(1 sor)
# select nextval('tmp_seq');
nextval
---------
1002
(1 sor)
# select nextval('tmp_seq');
nextval
---------
1003
(1 sor)
# select nextval('tmp_seq');
nextval
---------
1004
(1 sor)
# select nextval('tmp_seq');
nextval
---------
1005
(1 sor)
...
You can get up to 1000 (or the number specified as CACHE N)
numbers in a series (without holes) in he same client at once,
you don't even need to be in the same transaction.
Best regards,
Zoltán Böszörményi
--
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/
From | Date | Subject | |
---|---|---|---|
Next Message | Carson Farmer | 2009-05-19 16:57:14 | origins/destinations |
Previous Message | aravind chandu | 2009-05-19 16:37:32 | Error while including PQXX library |