序列使用 本页介绍天翼云TeleDB数据库的序列使用方法。 序列创建与访问 创建序列 plaintext teledb create sequence tseq; CREATE SEQUENCE 建立序列,不存在时才创建 plaintext teledb create sequence if not exists tseq; NOTICE: relation "tseq" already exists, skipping CREATE SEQUENCE 查看序列当前的使用状况 plaintext teledb select from tseq; lastvalue logcnt iscalled ++ 1 0 f (1 row) 获取序列的下一个值 plaintext teledb select nextval('tseq'); nextval 1 (1 row) 获取序列的当前值,这个需要在访问nextval()后才能使用 plaintext teledb select currval('tseq'); currval 1 (1 row) 设置序列当前值 plaintext teledb select setval('tseq',2); setval 2 (1 row) 序列在DML 中使用 plaintext teledb insert into tupdate values(nextval('tseq'),'teledb'); INSERT 0 1 teledb select from tupdate; id name age ++ 3 teledb (1 row) 序列作为字段的默认值使用 plaintext teledb alter table tupdate alter column id set default nextval('tseq'); ALTER TABLE teledb insert into tupdate(name) values('seqval'); INSERT 0 1 teledb select from tupdate; id name age ++ 3 teledb 4 seqval (2 rows) 序列作为字段类型使用 plaintext teledb