我有一个从迁移MSSQL
到PostgreSQL(9.2)
.
该数据库有 100 多个表,这些表具有自动编号字段(主键字段),下面给出的是表的示例
CREATE TABLE company
(
companyid integer NOT NULL DEFAULT nextval('seq_company_id'::regclass),
company character varying(100),
add1 character varying(100),
add2 character varying(100),
add3 character varying(100),
phoneoff character varying(30),
phoneres character varying(30)
CONSTRAINT gcompany_pkey PRIMARY KEY (companyid)
)
样本数据
INSERT INTO company (company, add1, add2, add3, phoneoff, phoneres) VALUES
('company1','add1','add2','add3','00055544','7788848');
INSERT INTO company (company, add1, add2, add3, phoneoff, phoneres) VALUES
('company2','add9','add5','add2','00088844','7458844');
INSERT INTO company (company, add1, add2, add3, phoneoff, phoneres) VALUES
('company5','add5','add8','add7','00099944','2218844');
下面是sequence
这张桌子
的
CREATE SEQUENCE seq_company_id
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
ALTER TABLE seq_company_id
OWNER TO postgres;
在阅读我阅读的 PostgreSQL 文档时Serial Types
,我希望将所有现有的自动编号字段更改为串行。怎么做?
我试过了
alter table company alter column companyid type serial
ERROR: type "serial" does not exist
********** Error **********