Re: Get block of N numbers from sequence

Поиск
Список
Период
Сортировка
От Boszormenyi Zoltan
Тема Re: Get block of N numbers from sequence
Дата
Msg-id 4A12E072.6090204@cybertec.at
обсуждение исходный текст
Ответ на Get block of N numbers from sequence  (Thomas Guettler <hv@tbz-pariv.de>)
Ответы Re: Get block of N numbers from sequence  (Thomas Guettler <hv@tbz-pariv.de>)
Список 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/


В списке pgsql-general по дате отправления:

Предыдущее
От: aravind chandu
Дата:
Сообщение: Error while including PQXX library
Следующее
От: Carson Farmer
Дата:
Сообщение: origins/destinations