`
CREATE TABLE aaa(
– pg10新特性,
id int generated always as identity (cache 100 START WITH 1 INCREMENT BY 1) primary key ,
id2 serial8,
c1 varchar(8)
)
INSERT INTO aaa(c1) values(‘第一行’);
ALTER TABLE aaa ADD COLUMN c2 int;
– 多列共用自增
ALTER TABLE aaa ALTER COLUMN c2 SET DEFAULT nextval(‘aaa_id2_seq’::regclass);
INSERT INTO aaa(c1) values(‘第二行’);
SELECT * FROM aaa;
id | id2 | c1 | c2 |
---|---|---|---|
1 | 1 | “第一行” | null |
2 | 2 | “第二行” | 3 |
`