Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Postgres函数返回数字0-7循环?_Sql_Postgresql - Fatal编程技术网

Sql Postgres函数返回数字0-7循环?

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

如何编写一个函数,以“线程安全”的方式返回例如数字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 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)

创建一个序列