1、创建序列
CREATE
SEQUENCE
if
not
exists test_mergetable_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 999999999
START 1
CACHE 1;
//或者:
create
sequence
if
not
exists test_mergetable_id_seq increment
by
1 minvalue 1
no
maxvalue start
with
1;
2、指定序列(给表的主键指定创建好的序列)
alter table test_mergetable alter column "i_id" set default nextval('test_mergetable_id_seq');
3、设置序列自增长从当前最大值开始
SELECT setval('test_mergetable_id_seq', (SELECT MAX(i_id) FROM test_mergetable));
alter sequence test_mergetable_id_seq start with 12;
4、删除序列
drop sequence IF EXISTS test_mergetable_id_seq
5、查看序列
select nextval(seq_ commodity);返回下一个序列号后
select currval(seq_ commodity);返回当前的序列号
标签:postgresql,seq,sequence,mergetable,test,序列,基本操作,id From: https://www.cnblogs.com/zhenren001/p/16952173.html