Sql Postgres函数返回数字0-7循环?
如何编写一个函数,以“线程安全”的方式返回例如数字0-7循环,确保每次调用都有一个新的数字(如果>7,则环绕) 它应该是一个全局函数,因此,如果“连接1”调用它并获得数字3,则“连接2”在调用时应获得数字4,依此类推。根据,您可以循环顺序:Sql Postgres函数返回数字0-7循环?,sql,postgresql,Sql,Postgresql,如何编写一个函数,以“线程安全”的方式返回例如数字0-7循环,确保每次调用都有一个新的数字(如果>7,则环绕) 它应该是一个全局函数,因此,如果“连接1”调用它并获得数字3,则“连接2”在调用时应获得数字4,依此类推。根据,您可以循环顺序: t=# create sequence rr07 minvalue 0 maxvalue 7 cycle; CREATE SEQUENCE t=# select nextval('rr07'); nextval --------- 0 (1
t=# create sequence rr07 minvalue 0 maxvalue 7 cycle;
CREATE SEQUENCE
t=# select nextval('rr07');
nextval
---------
0
(1 row)
t=# select nextval('rr07');
nextval
---------
1
(1 row)
t=# select nextval('rr07');
nextval
---------
2
(1 row)
t=# select nextval('rr07');
nextval
---------
3
(1 row)
t=# select nextval('rr07');
nextval
---------
4
(1 row)
t=# select nextval('rr07');
nextval
---------
5
(1 row)
t=# select nextval('rr07');
nextval
---------
6
(1 row)
t=# select nextval('rr07');
nextval
---------
7
(1 row)
t=# select nextval('rr07');
nextval
---------
0
(1 row)
创建一个序列