PostgreSQL/Sequence/nextval — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 13:14, 26 мая 2010
Using nextval function to get sequence next value
<source lang="sql">
postgres=# postgres=# postgres=# CREATE SEQUENCE myseq MINVALUE 0; CREATE SEQUENCE postgres=# postgres=# -- Using currval(?) postgres=# postgres=# SELECT currval("myseq"); ERROR: currval of sequence "myseq" is not yet defined in this session postgres=# postgres=# postgres=# drop sequence myseq; DROP SEQUENCE postgres=# postgres=# -- Setting a sequence value postgres=# CREATE SEQUENCE myseq MINVALUE 0; CREATE SEQUENCE postgres=# postgres=# SELECT setval("myseq", 1010);
setval
1010
(1 row) postgres=# postgres=# SELECT nextval("myseq");
nextval
1011
(1 row) postgres=# postgres=# postgres=# SELECT setval("myseq", 1010, false);
setval
1010
(1 row) postgres=# postgres=# SELECT nextval("myseq");
nextval
1010
(1 row) postgres=# postgres=# drop sequence myseq; DROP SEQUENCE postgres=#
</source>