主键一般设置为Integer类型,并且自动增长,起始值为1,增量为1;有两种方法:
法一:在建表时
nextval(‘表名_主键_seq’::regclass)
法二:如果表已经建好
CREATE SEQUENCE 表名_主键_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table 表名 alter column id set default nextval('表名_主键_seq');
//修改主键起始值:
alter sequence if exists 表名_主键_seq restart with 3 cache 1;
PostgreSQL 9中文手册:http://www.postgres.cn/docs/9.3/functions-sequence.html