Search Postgresql Archives

Re: Get block of N numbers from sequence

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

 



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/


-- 
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